![](/img/trans.png)
[英]How to count number of white and black pixels in color picture in python? How to count total pixels using numpy
[英]Using opencv / Numpy to find white pixels in a color image using python
我有一个使用opencv加载的图像,我想找到白色的像素。
input_img = [[[255,255,255], [0,127,255]],
[[255,255,255], [255,127,255]]]
应该回来
white = [[1, 0],
[1, 0]]
有没有一种方法可以做到这一点而无需重塑或不需要昂贵的for循环? 使用类似numpy.where的东西?
怎么样
(input_img == 255).all(axis=2)
这应该做
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.