1 | initial version |
You should use mask :
Mat image=imread("f:/lib/opencv/samples/data/lena.jpg",IMREAD_GRAYSCALE);
Mat mask = image<100;
image.setTo(255,mask);
imshow("r",image);
waitKey();
2 | No.2 Revision |
You should use mask :
Mat image=imread("f:/lib/opencv/samples/data/lena.jpg",IMREAD_GRAYSCALE);
Mat mask = image<100;
image.setTo(255,mask);
imshow("r",image);
waitKey();
if you want to change a gray level in red you have to convert your image first
Mat imageColor;
cvtColor(image, imageColor,CV_GRAY2BGR);
imageColor.setTo(Scalar(0,0,255),mask);
imshow("rc", imageColor);
waitKey();
3 | No.3 Revision |
You should use mask :
Mat image=imread("f:/lib/opencv/samples/data/lena.jpg",IMREAD_GRAYSCALE);
Mat mask = image<100;
image.setTo(255,mask);
imshow("r",image);
waitKey();
if you want to change a gray level in red you have to convert your image first
Mat imageColor;
cvtColor(image, imageColor,CV_GRAY2BGR);
imageColor.setTo(Scalar(0,0,255),mask);
imshow("rc", imageColor);
waitKey();
4 | No.4 Revision |
You should use mask :
Mat image=imread("f:/lib/opencv/samples/data/lena.jpg",IMREAD_GRAYSCALE);
Mat mask = image<100;
image.setTo(255,mask);
imshow("r",image);
waitKey();
if you want to change a gray level in red you have to convert your image first
Mat imageColor;
cvtColor(image, imageColor,CV_GRAY2BGR);
imageColor.setTo(Scalar(0,0,255),mask);
imshow("rc", imageColor);
waitKey();
If your image is in color use inRange :
Mat image = imread("f:/lib/opencv/samples/data/lena.jpg", IMREAD_COLOR);
Mat mask;
inRange(image,Vec3b(0,0,0),Vec3b(100,100,100),mask);
image.setTo(Vec3b(0,0,255), mask);
imshow("r", image);
waitKey();