Hue thresholding [closed]
I have calculated hue histogram then filtered pixels of the source image with low hue numbers. Threshold is marked by vertical white line on the histogram.
Can anybody explain why such poor results?
Here is the code:
cvtColor(src, src2, CV_BGR2HSV);
float peak_hue = peak_ind * bin_range;
float peak_hue1 = peak_hue - 2 * bin_range;
float peak_hue2 = peak_hue + 2 * bin_range;
Mat src4(src2.size(), CV_8UC3, Scalar(0, 0, 0));
Mat src5;
for (int i = 0; i < src2.rows; i++) {
for (int j = 0; j < src2.cols; j++) {
pix = src2.at<Vec3b>(i, j);
if (peak_hue1 <= pix[0] && pix[0] < peak_hue2) { //h
src4.at<Vec3b>(i, j) = pix;
}
}
}
cvtColor(src4, src5, CV_HSV2BGR);
imshow("Extracted foreground", src5);
and where's your code ?
comments : use inRange instead for loop. You will get a mask and then setTo to change pixel value
@LBerger. It is not
in range
. If you looking at pic on right side. you see alot of noising. Meant, if the valuse is too lower, you get alot of nosies. Set to higher valuies, will do a good job. Youn have to play around with it.inRange should work too, only it requires more arrays so consumes more memory. This may be a problem for large images.
@ya_ocv_user consumes more memory? you can give a scalar for parameter lowerb and higjherb
This is better, but still mask is an array.