【问题标题】:fast pixels processing using np.isin and np.where [issue]使用 np.isin 和 np.where 进行快速像素处理 [issue]
【发布时间】:2019-09-06 11:09:45
【问题描述】:

我是 python 和图像处理的新手。我正在尝试使用 np.isin 和 np.where 在输入图像中查找给定 RGB 值的列表(我想避免在所有像素上进行嵌套循环)。 所以,这里是输入和输出

输入:https://imgur.com/eNylzA9

输出:https://imgur.com/lDctkj9

我正在使用以下代码 -

fliterlist = [
    [244,240,255],
    [253,239,255],
    [255,234,249],
    [255,230,245],
    [255,229,243],
    [255,228,242]
]
# actual list has more than 100 elements

def imageTest(img,count=0):

    outImg = np.zeros(img.shape,dtype=np.uint8)

    posArray=(np.isin(img,bb)).all(axis=2)
    outImg[np.where(posArray)] = [255,255,255]

    outname = './fast/imageTest_'+str(count)+'.jpg'
    outputlist[outname]=outImg

    return

由于某种原因,我没有得到预期的输出。我的意思是,如果我使用双嵌套循环来迭代所有像素,我会得到想要的结果。但在这里看起来 np.isin 给了我一个不同的结果。 请帮我确定问题。

这是完美运行的示例想法 -

图片 - https://imgur.com/zP3zuLj

【问题讨论】:

  • 您能具体说明一下您要做什么吗?我可以理解您正在尝试对图像进行阈值处理。
  • 假设有一个图像。我需要找出其中的特定 RGB 值。例如,假设我正在寻找所有值为 [255,0,0] 的像素。所以输出图像基本上是黑色图像,只有那些像素标记为 [255,255,255]。有帮助吗?

标签: python-3.x numpy opencv


【解决方案1】:

使用opencv的inrange函数,如下:

mask = cv2.inRange(image, lower_range, upper_range)

我知道您想找到一个特定的像素,因此请相应地调整范围。 以我的经验,无论您尝试完成什么任务,使用一定范围的像素都会更好,这将是有益的。不过以后看你自己了。

【讨论】:

    猜你喜欢
    • 2010-12-20
    • 1970-01-01
    • 2023-04-04
    • 2010-10-16
    • 2020-10-18
    • 2016-12-18
    • 1970-01-01
    • 2012-02-24
    相关资源
    最近更新 更多