# Is HSV supposed to look extremely blotchy in opencv?

Here is my input followed by its hsv converted output. If you look at the full size image, you can see that my hsv image is blocky and weird looking.

Here is the hue channel alone, you can see how poorly blocky it is here as well:

Is the blotchiness supposed to happen?

This is essentially all I'm doing in code:

Mat hsvImg;
cvtColor(srcImg, hsvImg, CV_RGB2HSV);
Mat channels[3];
split(hsvImg, channels);
imshow("Original", srcImg);
imshow("HSVImg", hsvImg);


When I google to see HSV images, I see stuff like this:

All the sample images I see don't look as insanely blocky as mine do. Am I doing something wrong?

edit retag close merge delete

Sort by » oldest newest most voted

Your image is mostly gray; so the "hue" parameter doesn't make much sense.

The hue parameter is the angle of a given color relative to the gray on the color wheel (see below).

Normally the hue parameter should be 0 in the gray areas, but every digital image has some noise, so the position of the color of the pixels on the hue circle varies a bit around the neutral gray. If a pixel is just a bit yellow, and the next one just a bit blue, the hue parameter will be opposite! (45° and 225°)

The blotches are because the JPG is a lossy compression and it compresses a lot the chrominance channel creating color blotches.

I suggest to test your method on a colorful image, you'll see the difference.

Anyway, as a general rule, when processing HSV (or HSL) images, use all the channels, not only the hue (e.g. to segmenta a color, instead of just (a<hue<b) use (a<hue<b)&(saturation>c)&(luminosity>d)).

more

Thanks! So basically, its blotchy because in the mostly grayimage there isnt much variance, and when there IS variance, its a big variance in weird blotches.

I ran a couple more images through my HSV and they look less blotchy. Images with more color:

http://i.imgur.com/qDHajOT.png

http://i.imgur.com/u7Mobtj.png

( 2015-04-09 12:10:44 -0500 )edit

If you load image using imread() then the image will be in BGR format, OpenCV use BGR color space in default. See How the image matrix is stored in the memory.

So you need use the appropriate macro in cvtColor(),

means, CV_RGB2HSV should be CV_BGR2HSV on cvtColor()

Note: I assume you haven’t used cvtColor() to convert BGR to RGB before HSV conversion.

more

1

Yes, I am using imread. So I changed it to use BGR2HSV instead of RGB2HSV as you suggested.

Now it looks like this (BGR to HSV): http://i.imgur.com/2oB9NHn.jpg

Instead of this (RGB TO HSV): http://i.imgur.com/Idyoy3N.jpg

It looks better, but still blocky. Is that expected?

( 2015-04-08 23:13:16 -0500 )edit

Yes, as kbarni said, this is expected due to the behavior of CCD and CMOS sensors. There will be considerable amount of noise being added to image (even though you don't wish for).

Here is the synthesized color sample shape image

And their hue channel image

In this synth image, there wont be any patches. Hope you are clear now.

more

Official site

GitHub

Wiki

Documentation