gpt4 book ai didi

python-3.x - 使用 np.isin 和 np.where [问题] 进行快速像素处理

转载 作者:太空宇宙 更新时间:2023-11-03 23:07:46 25 4
gpt4 key购买 nike

我是 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

最佳答案

使用opencv的inrange函数,如下:

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

我知道您想找到一个特定的像素,因此相应地调整范围。根据我的经验,无论您将尝试完成什么任务,使用一定范围的像素会更好,这样会很有帮助。但稍后由您决定。

关于python-3.x - 使用 np.isin 和 np.where [问题] 进行快速像素处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55706623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com