0

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 Answers1

1

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.

alexisrozhkov
  • 1,623
  • 12
  • 18
  • You mean to say, I should check the distance between the lowest and highest values in 2 ways. 1) clockwise and 2) anti-clockwise. Then finally which ever gives the minimum distance we should consider that range. e.g. is low hue = 20 and high hue = 150 then clockwise distance is 130 and anticlock wise distance is (180-150) + 20 = 50. So in this case is should check h > 150 || h < 20. – Pranay Soni Mar 10 '17 at 06:56
  • Not necessarily. It is up to you to decide which sector of the circle you need, it doesn't have to be a smaller one. – alexisrozhkov Mar 10 '17 at 08:21