0
votes

I wanted to binarize a color image in HSV color space using inRange function of opencv.

I found that with some RGB values, hue value drastically changes. For e.g. 1) RGB Value: 56, 40, 39 Its HSV Value: 2, 77, 56 2) RGB Value: 56, 40, 41 Its HSV Value: 178, 73, 56

So, in this case both RGB colors are very close and also looks similar but its Hue value has huge difference, now if we use Hue range from 2 to 178 for binarization than its wrong.

So what should be the right way to binarize and image in HSV color space using threshold range.

1
@Miki has an excellent answer here... stackoverflow.com/a/32523532/2836621Mark Setchell

1 Answers

1
votes

You have to keep in mind that H component of HSV representation is cyclic, like numbers on a clock, with "canonical" range being [0, 360) (there are other options, like [0, 1) or [0, 180) that utilize different channel depths, in your case it's [0, 180) to fit into uchar range).

The easiest way to achieve what you want would be to iterate over image pixels yourself, check 2 conditions, something like this: (h > 170) || (h < 10) and assign binary values depending on whether this is true.

It can be helpful to draw the circle with your values and see what range do you want to cover and what expression should you use for that.