我需要修改以下算法,以便它可以从jpg图像中对RGB值列表进行排序。我用numpy和PIL得到了值。
from PIL import Image
import numpy as np
def maxList(A):
return(max(num for num in A))
def obtainDigit(num, n):
return (num // 10 ** n) % 10
def linkLists(A):
lAux = []
for sublist in A:
lAux.extend(sublist)
return(lAux)
def generateSublists(A, digito):
subListsAux = [[] for i in range(10)] //This 10 should be 255, since that is the max value for the RGB matrix numbers.
for num in A:
subListsAux[obtainDigit(num, digit)].append(num)
return(subListsAux)
def radixSort(A):
interations = len(str(maxList(A)))
for digit in range(iterations):
sublists = generateSublists(A, digit)
A = linkLists(sublists)
return(A)
image=Image.open("eliot.jpg")
image=np.array(image)
我需要的是使用image作为radixSort的参数。但首先我需要修改算法的某些部分,我只是不知道哪些部分。该算法适用于任何数字列表。