[SciPy-User] How to find local minimum of 1d histogram

Kevin Dunn kgdunn@gmail....
Fri Nov 27 16:31:32 CST 2009


> On Fri, Nov 27, 2009 at 4:12 PM, David Warde-Farley <dwf@cs.toronto.edu> wrote:
>>
>> On 27-Nov-09, at 2:49 PM, Michael Aye wrote:
>>
>>> The minimum between the gaussian-like peaks in the histogram shall be
>>> used as the masking limit to either show one or the other population
>>> of pixel intensities.
>>>
>>> My idea so far, but I'm not sure, if there is not a more obvious way?
>>> * Using interpolate1d to get a spline.
>>> * somehow get the coefficients of the spline function.
>>> * put them into poly1d
>>> * do derivative
>>> * get roots of derivative
>>
>> I had a similar problem, actually, and used
>> scipy.ndimage.gaussian_laplace, which will produce a smoothed discrete
>> second derivative. The minimum should be pretty easy to locate (it
>> will appear as a rather significant maximum peak in the transformed
>> curve).
>
> In a similar direction, I thought of using gaussian_kde to get a
> smoothed probability distribution. and look for local minimum.

Yet another way: Otsu's method [1], which is a standard algorithm in
image processing to segment an image.  There are other methods as
well.

When I've used Otsu's method from real-time image processing (under
unpredictable lighting), I use it only to provide a starting value.
Then you move left or right along the smoothed histogram (I normally
just use a moving average smoother, because other exotic smoothers
take too much time and don't improve accuracy that much) until you
land up in a minimum.

Usually the Otsu initial guess isn't far off, but it can be under some
circumstances.

[1] http://en.wikipedia.org/wiki/Otsu%27s_method (also see the
references at the bottom)

HTH,
Kevin

> Josef
>
>>
>> David
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User@scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user


More information about the SciPy-User mailing list