Code covered by the BSD License  

Highlights from
Min/Max filter

4.0 | 8 ratings Rate this file 80 Downloads (last 30 days) File Size: 28.7 KB File ID: #24705

Min/Max filter


Bruno Luong


12 Jul 2009 (Updated )

Multidimensional non-linear min/max filtering

| Watch this File

File Information

The filter computes the minima and/or maxima of an array over sliding window with a given size.

Multidimensional array is fully supported: running filter in 1D, 2D filter for image processing applications (erosion/dilatation), 3D and more.

This package has been implemented with a special care on the running speed: the MEX engine uses an algorithms that requires no more than three (3) comparisons per element and per dimension in all configurations.

All numerical and logical class arrays are supported.

Contributor (beside author) is Vaclav Potesil


This file inspired Free Knot Spline Approximation.

MATLAB release MATLAB 7.8 (R2009a)
Other requirements MEX correctly setup NO image processing is required Download a tiff file for Lena's demo
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (10)
15 Dec 2014 Christopher Volpe

Christopher Volpe

Stupid question: How is this different from simply doing an erosion (min) or dilation (max)? Or is this just for people who don't have the image processing toolbox?

Comment only
08 Dec 2014 ali


02 Nov 2014 seongjin


So far, this is the fastest that I know. Thank you.

24 May 2014 Wathsala Ranasinghe

Wathsala Ranasinghe

02 Sep 2013 Gerald Grabner

Gerald Grabner


20 Oct 2011 Qiao Liyong

Qiao Liyong

06 Oct 2011 shi


03 Oct 2010 Michael Teo

Michael Teo

Thanks for sharing, its make sense and it solved my problem. :)

03 Oct 2010 Bruno Luong

Bruno Luong

I copy the question from Michael Teo: Does it handle NaN data?

ePeriod = 3;
eData = [ 5;1;3;NaN;8;2;3;NaN;1;9 ];
minmaxfilt(eData, ePeriod, 'max', 'valid');

Actual output:

If we take NaN as a empty data, the expected output is:

The answer is "no". The work around id to replace NaN by -Inf for running max and +Inf for running min.

minmaxfilt(eData, ePeriod, 'max', 'valid')

Comment only
24 Mar 2010 Tobias


Nice Max-Filter. Works faster than implementation of Frederico D'Almeida and seems to be correct.

13 Jul 2009

Correct a bug that causes crash on 64-bit plateform
Additional memory check in one MEX function
Friendly matlab gateway for 1D min/max filtering

20 Sep 2009

New feature: Possibly to output corresponding indexes arrays (suggested by a user) + slight improvement of the Lemire's engine.

21 Sep 2009

Correct BUG of cropping the index array when shape is SAME

21 Sep 2009


22 Sep 2009

Cleaner algorithm for same shape filtering

26 Sep 2009


01 Dec 2009

Correct a small bug when "WIN" is a scalar and input array is vector (error wrongly issued)

Contact us