Search code examples
c++opencvimage-processing

How to judge color space of processed image?


I am studying the OpenCV. Now I am vary confusing the following problem.

Here is the code:

Mat img = imread("...");
Mat imgHSV;
Mat imgThresholded;

cvtColor(img, imgHSV, COLOR_BGR2HSV);
inRange(imgHSV, Scalar(150, 50, 75), Scalar(179, 255, 255), imgThresholded);

Now, I get a processed image imgThresholded. is this imgThresolded in RGB color space or HSV color space?


Solution

  • It is 1 a one channel image with either 0 or 255 values. If you want to go back to your original RGB space just do the following:

    cv::Mat FinalRGB;
    cv::cvtColor(imgThresholded, imgThresholded, CV_GRAY2BGR);
    cv::bitwise_and(imgThresholded, img, FinalRGB);
    

    EDIT: As @Micka stated:

    cv::Mat imgMasked; 
    img.copyTo(imgMasked, imgThresholded);
    

    will do the same idea but faster.