1
   def on_pushButtonTwo_clicked(self):
    img = np.asarray(Image.open("testtwo.tif").convert # read image, convert it('L'))                            
    img = 1 * (img < 127)

    areasplit = np.split(img.ravel(), 24) # here we are splitting converted to 1D array
    for i in areasplit:
     area = (i == 0).sum()
     print area

    maxr =  areasplit[argmax(sum(areasplit == 0, axis = 0)), :] # selecting subarrays with min and max white pixel numbers
    minr = areasplit[argmin(sum(areasplit == 0, axis = 0)), :]

    distance = cityblock(maxr, minr) # computing distance between subarrays
     print distance


    Result: type error: areasplit[argmax(sum(areasplit == 0, axis=0)), :]
    TypeError: list indices must be integers, not tuple

有没有办法选择具有最小和最大白色像素数的子阵列?如何正确更改代码?谢谢

4

1 回答 1

0

areasplit是 ndarrays 的列表,而不是 ndarray,因此它不能采用第二个索引。这应该有效:

maxr =  areasplit[argmax(sum(areasplit == 0, axis = 0))]
minr = areasplit[argmin(sum(areasplit == 0, axis = 0))]

或者,在这些调用之前将您的 ndarray 列表转换为 2D ndarray:

areasplit = numpy.array(areasplit)
于 2013-08-21T08:10:57.563 回答