[SciPy-user] median filter with clipping

Glen W. Mabey Glen.Mabey at swri.org
Wed May 16 16:19:40 EDT 2007


On Wed, May 16, 2007 at 03:31:02PM -0400, David Grumm wrote:
> I'm interested in finding a Python routine (or C routine I can call from 
> Python) that calculates a multi-dimensional** median filter of an array 
> while allowing pixels below a specified value to be excluded.   In iraf 
> there is a function median() which has such a parameter "zloreject", 
> which causes all pixels having values below zloreject to be ignored when 
> calculating the median for a given pixel. Median_filter() in SciPy's 
> ndimage calculates a median filter, but doesn't allow exclusion of 
> pixels.  Any thoughts are appreciated.

I have been doing precisely that with masked arrays (numpy.ma).  There
is also a maskedarray module in the scipy sandbox, but I haven't tried
it out.

data_ma = numpy.ma.array( data, mask=(data<thresh) )
med_res = numpy.median( data_ma.compressed() )

HTH,

Glen



More information about the SciPy-User mailing list