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
有没有办法选择具有最小和最大白色像素数的子阵列?如何正确更改代码?谢谢