Reputation: 313
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?
Upvotes: 2
Views: 177
Reputation: 20264
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.
Upvotes: 0
Reputation: 22954
As per the documentation,
void inRange(InputArray src, InputArray lowerb, InputArray upperb, OutputArray dst)
dst – output array of the same size as src and CV_8U type
This means that for 3 channel input image the output would be a single channel image, in case of thresholding, the output is a binary image which has only white(255) and black(0) pixels and the format is CV_8U only.
Upvotes: 1
Reputation: 45
inRange() will give binary image. Not HSV or RGB. But yeah, it will consider HSV image for computation as you have given imHSV as the input image.
The function inRange() works as follows:
imThresholded (I) is set to 255 (all 1 -bits) if imHSV (I) is within the specified 1D, 2D, 3D, ... box and 0 otherwise.
When the lower and/or upper boundary parameters are scalars, the indexes (I) at lowerb and upperb in the above formulas should be omitted.
Upvotes: 0