File Exchange

image thumbnail

Min/Max filter

version 1.7.0.1 (27.8 KB) by Bruno Luong
Multidimensional non-linear min/max filtering

11 Downloads

Updated 20 Sep 2018

View License

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

Cite As

Bruno Luong (2020). Min/Max filter (https://www.mathworks.com/matlabcentral/fileexchange/24705-min-max-filter), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (13)

Bruno Luong

To Adhithya: The algorithm reference is cited inside the source code LEMIRE_ENGINE.C

Adhithya

I am using your minmax filter for 3D data. Do you have any flowchart to understand how the long code works for min/max filter.

Is it possible to only get the summit locations?

Chris 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?

ali

seongjin

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

Fast!

Qiao Liyong

shi

Michael Teo

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

Bruno Luong

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

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

Actual output:
[5;3;3;NaN;8;3;3]

If we take NaN as a empty data, the expected output is:
[5;3;8;8;8;3;3]
</ENDQUOTE>

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

eData(isnan(eData))=-inf
minmaxfilt(eData, ePeriod, 'max', 'valid')

Tobias

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

Updates

1.7.0.1

Change MEX files to be compatible with R2018a MEX-API

1.7.0.0

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

1.6.0.0

description

1.5.0.0

Cleaner algorithm for same shape filtering

1.4.0.0

Acknowledgment

1.3.0.0

Correct BUG of cropping the index array when shape is SAME

1.2.0.0

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

1.1.0.0

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

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired: Free-knot spline approximation