[英]Using opencv / Numpy to find white pixels in a color image using python
I have an image I loaded using opencv, that I would like to find pixels that are white. 我有一个使用opencv加载的图像,我想找到白色的像素。
input_img = [[[255,255,255], [0,127,255]],
[[255,255,255], [255,127,255]]]
should return 应该回来
white = [[1, 0],
[1, 0]]
Is there a way to do this without reshaping or without an expensive for loop? 有没有一种方法可以做到这一点而无需重塑或不需要昂贵的for循环? Using something like numpy.where?
使用类似numpy.where的东西?
怎么样
(input_img == 255).all(axis=2)
This should do it 这应该做
input_img = [[[255,255,255], [0,127,255]],
[[255,255,255], [255,127,255]]]
white = np.array(np.sum(input_img, axis=-1) == 765, dtype=np.int32)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.