图像的 Numpy> 0
Numpy of image> 0
我先对图像进行了二值化处理,然后在 python 中对其进行了过滤。
现在如何将每个大于 0 的像素添加到 numpy 数组?
img = Image.open('native.png').convert('RGB')
binarised = img.convert('LA')
# binarised.save('binarised.png')
filtered = ndimage.median_filter(binarised, size = 27)
# Image.fromarray(filtered).save('filtered.png')
width, height = img.size
x = np.array([])
y = np.array([])
for column in range(width):
for line in range(height):
if(???): ### if pixel at column/line > 0 ###
x = np.append(x, column)
y = np.append(y, line)
试试这个:
if (filtered[column - 1, line - 1] > 0).all():
我先对图像进行了二值化处理,然后在 python 中对其进行了过滤。
现在如何将每个大于 0 的像素添加到 numpy 数组?
img = Image.open('native.png').convert('RGB')
binarised = img.convert('LA')
# binarised.save('binarised.png')
filtered = ndimage.median_filter(binarised, size = 27)
# Image.fromarray(filtered).save('filtered.png')
width, height = img.size
x = np.array([])
y = np.array([])
for column in range(width):
for line in range(height):
if(???): ### if pixel at column/line > 0 ###
x = np.append(x, column)
y = np.append(y, line)
试试这个:
if (filtered[column - 1, line - 1] > 0).all():