如何从一维子阵列的数组中选择具有最小和最大白色像素数的子阵列?

时间:2013-08-20 10:34:57

标签: opencv python-2.7 numpy scipy mahotas

如何从1D numpy子阵列数组中选择子阵列?

def distancesplit(self):
  img = np.asarray(Image.open("testtwo.tif").convert('L'))                            
  img = 1 * (img < 127)
  area = (img == 0).sum()
  areasplit = np.split(img, 24) # splitting an image array into 24
  print areasplit
for i in areasplit: # compute white pixel area in splitted parts-arrays
  result = (i == 0).sum()
  print result
for i in areasplit: #converting 2D array inro 1D 
  b = i.ravel()
# Now I need o select from "b" 1D array the subarrays  with minimal and maximal number of white pixels. I need it for distance metrics between these subarrays. Thank you.

1 个答案:

答案 0 :(得分:0)

在每个子矩阵(本例中为行或列)上使用sum函数(http://docs.opencv.org/modules/core/doc/operations_on_arrays.html#sum),然后从结果中查找最小值和最大值。