Ask Your Question

Revision history [back]

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();

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();

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();

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();