OpenCV将一种颜色转换为另一种颜色 [英] OpenCV converting one color to another

查看:1227
本文介绍了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

推荐答案

您可以执行以下操作。


  1. 使用 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 使用图片 .opencv.org / modules / core / doc / basic_structures.html?highlight = copy#void%20Mat%3a%3acopyTo%28OutputArray%20m%29%20constrel =nofollow> copyTo

Copy black_image (your desired substitute color) into your original image through mask using copyTo().

Mat black_image(image.size(), CV_8U, Scalar(0));  // all zeros image
black_image.copyTo(image, mask);


这篇关于OpenCV将一种颜色转换为另一种颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆