Ask Your Question

Revision history [back]

Hue thresholding

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.

image description

Can anybody explain why such poor results?

image description

Hue thresholding

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.

image description

Can anybody explain why such poor results?

image description

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