Opencv 如何根据每个子阵列中的白像素计数对NumPy子阵列进行排序? img=np.asarray(Image.open(“testtwo.tif”).convert('L'))#读取和转换图像 img=1*(img

Opencv 如何根据每个子阵列中的白像素计数对NumPy子阵列进行排序? img=np.asarray(Image.open(“testtwo.tif”).convert('L'))#读取和转换图像 img=1*(img,opencv,python-2.7,numpy,scipy,Opencv,Python 2.7,Numpy,Scipy,如何获得子阵列内部包含一定顺序的白色像素数的阵列 要计算子阵列中的零数,可以执行以下操作: img = np.asarray(Image.open("testtwo.tif").convert('L'))# reading and converting image img = 1 * (img < 127) arraysplit = np.split(img.ravel(), 24) # here we are spl

如何获得子阵列内部包含一定顺序的白色像素数的阵列

要计算子阵列中的零数,可以执行以下操作:

  img = np.asarray(Image.open("testtwo.tif").convert('L'))# reading and converting    image                         
  img = 1 * (img < 127)

   arraysplit = np.split(img.ravel(), 24) # here we are splitting converted to 1D array

您可以使用
key
关键字参数来
sorted
完成以下操作:

zeros = [(q==0).sum() for q in arraysplit]
然后,
splits_by_white_count
将是图像数据的分割列表,按白像素数的增加排序(假设您有8位图像数据)

若您只需要一个白像素计数列表,您可以按顺序对Christian的解决方案进行排序:

arraysplit = np.split(img.ravel(), 24)

splits_by_white_count = sorted(arraysplit, key=lambda a: (a == 256).sum())
你问了,但你从来没有接受过答案。请接受答案并停止反复发布相同的问题。
white_counts = sorted((a == 256).sum() for a in arraysplit)