简体   繁体   English

使用python使用opencv / numpy查找彩色图像中的白色像素

[英]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.

相关问题 如何计算python中彩色图片的黑白像素数? 如何使用 numpy 计算总像素 - How to count number of white and black pixels in color picture in python? How to count total pixels using numpy 如何使用opencv python将图像的alpha通道转换为白色? - how to convert alpha channel of the image to white color using opencv python? 如何通过在 python 中添加白色透明像素将图像增加到特定大小(最好使用 opencv) - How increase an image to a specific size by adding white transparent pixels in python (preferably using opencv) 数不了。 使用OpenCV的图像中的黑色到白色像素 - Counting the no. of black to white pixels in the image using OpenCV 使用 python opencv 跟踪白色 - Tracking white color using python opencv 使用opencv通过计数特定颜色的像素来识别图像 - Image recognizing with counting pixels of specific color, using opencv 使用终端在python中找到图像像素? - find image pixels in python using Terminal? 是否可以使用 Python 仅计算图像中的白色像素? - Is it possible to count white pixels only in an image using Python? 如何使用python计算二进制图像中的黑白像素 - how to count black and white pixels in binary image using python 使用 opencv、numpy 和 python 在图像中搜索像素 - Searching for a pixel in an image using opencv, numpy and python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM