Ask Your Question
2

Is HSV supposed to look extremely blotchy in opencv?

asked 2015-04-08 10:37:56 -0600

Jdban gravatar image

updated 2015-10-05 11:48:23 -0600

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.

image description

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

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: image description

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

edit retag flag offensive close merge delete

3 answers

Sort by » oldest newest most voted
7

answered 2015-04-09 08:26:40 -0600

kbarni gravatar image

updated 2015-04-09 08:28:04 -0600

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

hue circle

edit flag offensive delete link more

Comments

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

Jdban gravatar imageJdban ( 2015-04-09 12:10:44 -0600 )edit
1

answered 2015-04-08 22:50:44 -0600

Haris gravatar image

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.

edit flag offensive delete link more

Comments

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?

Jdban gravatar imageJdban ( 2015-04-08 23:13:16 -0600 )edit
0

answered 2015-04-28 01:11:12 -0600

Spark gravatar image

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

Color Image

And their hue channel image

Hue Channel

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

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2015-04-08 10:37:56 -0600

Seen: 7,336 times

Last updated: Apr 28 '15