peaks2 - find peaks in 2D data without additional toolbox

Find peaks in 2D data just as with Matlab's 'findpeaks' function
Updated 12 Apr 2023

View License

Fast and effective 2D peak finding algorithm returning peak locations and values. Accepts 2D arrays as an input (for instance, image acquired with a camera from some optics experiment). Various filters can be selected such as the minimal absolute value or threshold above the immediate surroundings etc.
It mimicks the same syntax as Matlab's own 'findpeaks' function but does not require any additional Matlab toolbox, just the base program.
MinPeakHeight, Threshold and MinPeakDistance parameters are accepted, just like in the original 'findpeaks' function:
● MinPeakHeight simply filters out those peaks lower than this absolute value;
● Threshold only retains those peaks higher than its immediate neighbors by the specified threshold value;
● MinPeakDistance specifies the minimal Cartesian circle around which weaker peaks are 'shadowed' and removed;
● as of this moment, peak prominence is not implemented yet.
The idea behind the algorithm is simple yet effective. The 2D peak finding algorithm works by comparing each point to its immediate surroudings (all 8 points around: left, rihgt, top, bottom etc.) in an vectorised fashion. This guarantees minimal execution time. A point is considered as a peak if it is strictly greater than its immediate neighbors all around.

Cite As

Kristupas Tikuišis (2024). peaks2 - find peaks in 2D data without additional toolbox (, MATLAB Central File Exchange. Retrieved .

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

Inspired: Mobile Phone Astrometry Explorer

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes

In the new MinPeakDistance filter, the final peak list was not updated. Now corrected.


Minimal polishing of the description


The code cleaned a bit, no other real changes


MinPeakDistance functionality added


Updated image


Updated description


I simply updated the description of the function, as well as proper tagging. No code change this time.