Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Noisy hue in OpenCV

this question is regarding opencv with c++ in VS2008 express.

I'm doing very simple thing. Trying to get skin values from camera image.

As you can see in the screenshot camera image looks fairly good. I'm converting it to HSV & separating Hue channel from that to later threshold the skin value. But Hue channel seems too much noisy & grainy. Also HSV image window shows degradation of information. Why is that happening? & how to solve that. If we cant can we remove noise by some kind of smoothing? Code is as below :

#include <opencv2/opencv.hpp>
int main(){
    cv::VideoCapture cap(0); // open the default camera   
    cv::Mat hsv, bgr, skin;//make image & skin container
    cap >> bgr; 
    //cvNamedWindow("Image");
    //cvNamedWindow("Skin");    
    //cvNamedWindow("Hue");
    cv::cvtColor(bgr, hsv, CV_BGR2HSV);
    std::vector<cv::Mat> channels;
    cv::split(hsv, channels);
    cv::Mat hue;
    hue = channels[0];  
    cv::imshow("Image", bgr);cvMoveWindow("Image",0,0);
    cv::imshow("HSV", hsv);cvMoveWindow("HSV",660,0);
    cv::imshow("Hue", hue);cvMoveWindow("Hue",0,460);   

    cvWaitKey(0);//wait for key press   
    return 0;   
}

enter image description here

like image 873
Rajdeep Avatar asked Mar 03 '13 18:03

Rajdeep


2 Answers

Hue channel seems too much noisy & grainy. Why is that happening?

In the real-world colors we see, the portion of information that is represented by "hue" varies. The color red is completely described by hue. Black has no hue information at all.

However, when a color is represented in HSV as you have done, the hue is always one-third of the color information.

So as colors approach any shade of gray, the hue component will be artificially inflated. That's the graininess you're seeing. The closer to gray, the more hue must be amplified, including error in captured hue.

Also HSV image window shows degradation of information. Why is that happening?

There will be rounding errors in the conversion, but it's probably not as much as you think. Try converting your HSV image back to BGR to see how much degradation actually happened.

& how to solve that.

Realistically, you have two options.

Use a higher-quality camera, or don't use HSV format.

like image 85
Drew Dormann Avatar answered Sep 29 '22 12:09

Drew Dormann


If you look at the formulae in the OpenCV documentation for the function cvtColor with parameter CV_BGR2HSV you will have

enter image description here

enter image description here

enter image description here

Now, when you have a shade of gray, i.e. when R is equal to B and R is equal to G, the fraction in the H formula is always undefined since it is zero divided by zero. It seems to me that the documentation does not describe what happens in that case.

like image 42
Alessandro Jacopson Avatar answered Sep 29 '22 12:09

Alessandro Jacopson