MinimaMaxima3D

Find the minima and maxima in a 3D Cartesian data space
2.9K Downloads
Updated 14 Dec 2007

View License

V 1.0 Dec 13, 07
Author Sam Pichardo.
This function finds the local minima and maxima in a 3D Cartesian data.
It's assumed that the data is uniformly distributed.
The minima and maxima are calculated using a multi-directional derivation.

Use:

[Maxima,MaxPos,Minima,MinPos]=MinimaMaxima3D(Input,[Robust],[LookInBoundaries],[numbermax],[numbermin])

where Input is the 3D data and Robust (optional and with a default value
of 1) indicates if the multi-directional derivation should include the
diagonal derivations.

Input has to have a size larger or equal than [3 x 3 x 3]

If Robust=1, the total number of derivations taken into account are 26: 6
for all surrounding elements colliding each of the faces of the unit cube;
10 for all the surrounding elements in diagonal.

If Robust =0, then only the 6 elements of the colliding faces are considered

The function returns in Maxima and MaxPos, respectively,
the values (numbermax) and subindexes (numbermax x 3) of local maxima
and position in Input. Maxima (and the subindexes) are sorted in
descending order.
Similar situation for Minima and MinimaPos witn a numbermin elements but
with the execption of being sorted in ascending order.

IMPORTANT: if numbermin or numbermax are not specified, ALL the minima
or maxima will be returned. This can be a useless for highly
oscillating data

LookInBoundaries (default value of 0) specifies if a search of the minima/maxima should be
done in the boundaries of the matrix. This situation depends on the
the desire application. When it is not activated, the algorithm WILL NOT
FIND ANY MINIMA/MAXIMA on the 6 layers of the boundaries.
When it is activated, the finding minima and maxima on the boundaries is done by
replicating the extra layer as the layer 2 (or layer N-1, depending of the boundary)
By example (and using a 2D matrix for simplicity reasons):
For the matrix
[ 4 1 3 7
5 7 8 8
9 9 9 9
5 6 7 9]

the calculation of the partial derivate following the -x direction will be done by substrascting
[ 5 7 8 8
4 1 3 7
5 7 8 8
9 9 9 9]
to the input. And so on for the other dimensions.
Like this, the value "1" at the coordinate (1,2) will be detected as a
minima. Same situation for the value "5" at the coordinate (4,1)
%%%%%%%%%%%%%%%%

This function was inspired by extreme2.m of C.A. Vargas, even if I followed a somewhat different approach for the spatial derivation.

The biggest advantage is that the function is fast (at least for my 500k elements matrices) and, I hope, the code is quite simple.

Enjoy and let me know your thoughts

Cite As

Samuel Pichardo (2024). MinimaMaxima3D (https://www.mathworks.com/matlabcentral/fileexchange/17997-minimamaxima3d), MATLAB Central File Exchange. Retrieved .

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

Inspired by: extrema.m, extrema2.m

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0