[SciPy-user] Extrema finding

David Bolme bolme1234 at comcast.net
Thu Oct 9 15:06:33 EDT 2008


This is a version for finding extrema in a 2D array.  It requires the  
ndimage maximum/minimum filters.  For the one dimensional case  
substitute size=[3] or use maximum_filter1d.  I keep writing this code  
over and over.  I am surprised that there is not a general purpose  
extrema finding routine in scipy.

     def localMax(mat):
         mx = maximum_filter(mat, size=[3,3])
         mn = minimum_filter(mat, size=[3,3])
	
         # (mat == mx) true if pixel is equal to the local max
         # The next computation suppresses responses where
         # the function is flat.
         local_maxima = ((mat == mx) & (mat != mn))
	
         # Get the indices of the maxima
         extrema = nonzero(local_maxima)
         return extrema


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20081009/049f0c03/attachment.html>


More information about the SciPy-User mailing list