Ask Your Question

Calculate hue distance from hue histogram?

asked 2019-12-11 22:00:49 -0500

NhiDang gravatar image

I'm currently making an object model by using HSV color histogram. As visually similar colors may have very different hue values (eg. 1 degree and 359 degree are similar red hues), Hue Distance is suggested instead of the Hue Component.

My goal is to implement the distance function from the reading below but I have so many questions in my mind :(

image description

First, is H represent the hue value extracted from each hsv_image pixel or is it represent each bin in the original histogram where I extracted the Href ?

Second, if I use the function minVal, maxVal, minLoc, maxLoc = cv2.minmaxLoc(hue_histogram) to find the Href, is Href = maxVal or Href = maxLoc? If Href = maxLoc, will Href be a bin holding a range of hue value in the histogram? If so, how do I apply Href, which is a range of value, to this distance function?

Thank you so much!

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2019-12-12 03:57:00 -0500

kbarni gravatar image

If I understand correctly, instead of using the real hue value of the pixels in your processing, you will use a Hue value relative to a reference. It's like rotating the hue circle. So you'll have H=0 not for red, but for the predominant color.

For you Href is the maxLoc (the position of the maximum value in the Hue histogram). You can check it by analyzing a predominantly green image to get a Href around 120°.

In a histogram, even if you have bins, you can associate the bin to a value. You can take the lower limit of the bin or (better) the middle value. So if you have 36 bins, each representing 10° of range, and maxLoc=2, than you can take Href = 2*10+5 = 25° or eventually Href = 2*10 = 20°. The first one is better, but I don't think this will have an impact on the results.

After you found the Href, you'll have to recalculate the H value of every pixel using the formula from the article.

Note: I don't know the article you are using, but to calculate distance between colors we often use the Lab color space. Thee, the perceptual distance between two colors is equal to the eucledian distance. With the hue distance you can have very distant values for similar colors around the neutral grey.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2019-12-11 22:00:49 -0500

Seen: 310 times

Last updated: Dec 12 '19