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

Fri Nov 27 18:43:42 CST 2009

```Thanks to you all, love this forum!
That will keep me busy on the weekend! ;)

BR,
Michael

On Nov 27, 11:31 pm, Kevin Dunn <kgd...@gmail.com> wrote:
> > On Fri, Nov 27, 2009 at 4:12 PM, David Warde-Farley <d...@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-U...@scipy.org
> >>http://mail.scipy.org/mailman/listinfo/scipy-user
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-U...@scipy.orghttp://mail.scipy.org/mailman/listinfo/scipy-user
```