1

我首先对图像进行二值化,然后在 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)
4

1 回答 1

1

尝试这个:

        if (filtered[column - 1, line - 1] > 0).all():
于 2021-08-29T04:53:38.320 回答