【问题标题】:Numpy of image> 0图片数量> 0
【发布时间】:2021-10-28 08:52:12
【问题描述】:

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

【问题讨论】:

    标签: python image numpy scipy ndimage


    【解决方案1】:

    试试这个:

            if (filtered[column - 1, line - 1] > 0).all():
    

    【讨论】:

    • 我得到“ValueError:具有多个元素的数组的真值不明确。使用 a.any() 或 a.all()”:/
    • 编辑了我的答案,现在应该可以使用了,如果可行,请接受并投票。
    • print(filtered.shape) 给了什么?
    • 更新了我的答案,现在试试吧!
    • 啊,这就是我接下来要编辑的内容
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-17
    • 2021-04-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多