python-3.x - 使用 np.isin 和 np.where 进行快速像素处理 [issue]
问题描述
我是 python 和图像处理的新手。我正在尝试使用 np.isin 和 np.where 在输入图像中查找给定 RGB 值的列表(我想避免在所有像素上进行嵌套循环)。所以,这里是输入和输出
我正在使用以下代码 -
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 给了我一个不同的结果。请帮我确定问题。
这是完美工作的示例想法 -
解决方案
使用opencv的inrange函数,如下:
mask = cv2.inRange(image, lower_range, upper_range)
我知道您想找到一个特定的像素,因此请相应地调整范围。根据我的经验,无论您尝试完成什么任务,使用一定范围的像素都会更好,这将是有益的。但以后取决于你。
推荐阅读
- amazon-web-services - AWS redis set expire 无法正常工作
- c# - 如何根据运行时选择的属性名称从对象中获取特定属性
- javascript - 具有百分比宽度导航栏的可滚动页面
- python - 如何遍历数组?
- java - 在 Caffeine 中使用 AsyncCache 手动加载和删除条目
- javascript - SocketIO 不起作用,没有显示控制台消息
- vue.js - 在操作中发送发布请求并使用 vuex 提交数据更改
- python - 列表乘法创建别名列表,而不是像其他类型那样单独的实体
- azure-devops - AzDevOps 队列恢复默认权限
- excel - 尝试创建一个循环以将单元格从一张纸复制到另一张纸