OpenCV将一种颜色转换为另一种颜色 [英] OpenCV converting one color to another
本文介绍了OpenCV将一种颜色转换为另一种颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个灰度图像
我想将所有的白色像素(纯白色 - 255)转换为黑色(0)
只有那些颜色,而不是所有的灰度
如何我这样做?
谢谢!
Ron
I have a greyscale image I would like to convert all the white pixels (pure white - 255) to black (0) only those colors, not all the greyscale How can I do this? Thank you! Ron
推荐答案
您可以执行以下操作。
-
使用
inRange()
。
Mat image; // your original image
Mat mask;
void inRange(image, Scalar(255), Scalar(255), mask)
输出 mask
将是一个二进制掩码,如果 image
中的相应像素等于255,则其像素设置为255
The output mask
will be a binary mask where its pixel is set to 255 if the corresponding pixel in image
equals to 255 (that is if the pixel value is between 255 and 255, boundaries are inclusive).
复制 black_image