Rajdeep Rajdeep - 28 days ago 11
C++ Question

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

Answer

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

In the real-world colors we see, the amount of information represented by "hue" varies. The color red is completely described by hue. Black has no hue 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.