Skip to content Skip to sidebar Skip to footer

Selecting Best Range Of Values From Histogram Curve

Scenario : I am trying to track two different colored objects. At the beginning, user is prompted to hold the first colored object (say, may be a RED) at a particular position in f

Solution 1:

If I understand right, the only thing you need here is to find a maximum in a graph, where the maximum is not necessarily the highest peak, but the area with largest density.

Here's a very simple not too scientific but fast O(n) approach. Run the histogram trough a low pass filter. E.g. a moving average. The length of your average can be let's say 20. In that case the 10th value of your new modified histogram would be:

mh10 = (h1 + h2 + ... + h20) / 20

where h1, h2... are values from your histogram. The next value:

mh11 = (h2 + h3 + ... + h21) / 20

which can be calculated much easier using the previously calculated mh10, by dropping it's first component and adding a new one to the end:

mh11 = mh10 - h1/20 + h21/20

Your only problem is how you handle numbers at the edge of your histogram. You could shrink your moving average's length to the length available, or you could add values before and after what you already have. But either way, you couldn't handle peaks right at the edge.

And finally, when you have this modified histogram, just get the maximum. This works, because now every value in your histogram contains not only himself but it's neighbors as well.

A more sophisticated approach is to weight your average for example with a Gaussian curve. But that's not linear any more. It would be O(k*n), where k is the length of your average which is also the length of the Gaussian.

Post a Comment for "Selecting Best Range Of Values From Histogram Curve"