Very fast 2D local maxima
Version 1.0.1 (2.1 KB) by
George Heath
Detects local maxima (peaks) in a 2D image above a specified intensity threshold, neighborhood, and optionally filters peaks by prominence
A very fast local maxima (peak detector) for 2D images using morphological maximum filtering. Ideal for video analysis when used in a loop.
User can define intensity threshold, local neighborhood and optionally filters peaks by prominence.
USAGE:
Example 1 (defult): locs = Fast_peaks2D(Img, thresh, kernel_size)
Example 2 (with prominence): locs = Fast_peaks2D(Img, thresh, kernel_size, min_prom)
Example 3 (for multiple frames):
locs = [];
for i = 1:numel(img(1,1,:))
li = Fast_peaks2D(img(:,:,i), LAFM_thresh, 1);
li = [li, i*ones(numel(li(:,1)),1)];
locs = [locs; li];
end
INPUTS:
Img - 2D image (grayscale, numeric matrix) for peak detection.
thresh - Intensity threshold; only peaks above this value are considered.
kernel_size - Size of the local neighborhood used for maximum filtering (in pixels).
min_prom - (Optional) Minimum required prominence of peaks. Peaks with lower prominence are discarded.
OUTPUT:
locs - Nx4 array where each row represents a detected peak:
[x_position, y_position, peak_height, prominence]
If min_prom is not provided, prominence is set to zero.
ISSUE: Over picks peaks on featureless or uniform regions
NOTES:
- The function uses morphological maximum filtering and optional prominence filtering.
- Edge pixels (within 2 pixels of the image boundary) are excluded from detection.
- Prominence is computed as the vertical distance to the lowest point along the path to the nearest higher neighboring peak. Prominence calculations slow the code down.
Cite As
George Heath (2025). Very fast 2D local maxima (https://uk.mathworks.com/matlabcentral/fileexchange/181437-very-fast-2d-local-maxima), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2025a
Compatible with any release
Platform Compatibility
Windows macOS LinuxTags
Acknowledgements
Inspired by: NanoLocz - AFM Image Analysis Platform
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
