skimage2.feature.peak_local_max#
- skimage2.feature.peak_local_max(image, *, min_distance=1, threshold_abs=None, threshold_rel=None, exclude_border=1, num_peaks=None, footprint=None, labels=None, num_peaks_per_label=None, p_norm=2.0)[source]#
Find peaks in an image as coordinate list.
Peaks are the local maxima in a region of
floor(2 * min_distance + 1)(i.e. peaks are separated by at leastmin_distance).If both
threshold_absandthreshold_relare provided, the maximum of the two is chosen as the minimum intensity threshold of peaks.- Parameters:
- imagendarray
Input image.
- min_distancefloat, optional
The minimal allowed distance separating peaks. To find the maximum number of peaks, use
min_distance=1. See alsop_norm.- threshold_absfloat, optional
Minimum intensity of peaks. By default, the absolute threshold is the minimum intensity of the image.
- threshold_relfloat, optional
Minimum intensity of peaks, calculated as
max(image) * threshold_rel.- exclude_borderint or tuple of (int, …), optional
Control peak detection close to the border of
image. By default, only peaks exactly on the border are excluded.0Distance to border has no effect, all peaks are identified.
- positive integer
Exclude peaks that are within this distance of the border.
- tuple of positive integers
Same as for a single integer but with different distances for each respective dimension.
The value of
p_normhas no impact on this border distance.- num_peaksint, optional
If given, maximum number of allowed peaks. When the number of peaks exceeds
num_peaks, returnnum_peakspeaks based on highest peak intensity.- footprintndarray of dtype bool, optional
Binary mask that determines the neighborhood (where
True) in which a peak must be a local maximum (see Notes). If not given, defaults to an array of ones of sizefloor(2 * min_distance + 1).- labelsndarray of dtype int, optional
If provided, each unique region
labels == valuerepresents a unique region to search for peaks. Zero labels are reserved for background.- num_peaks_per_labelint, optional
If given, maximum number of peaks for each label.
- p_normfloat, optional
Which Minkowski p-norm to use. Should be in the range [1, inf]. A finite large p may cause a ValueError if overflow can occur.
infcorresponds to the Chebyshev distance and 2 to the Euclidean distance. See alsonumpy.linalg.norm().
- Returns:
- outputndarray of shape (N, D)
The coordinates of the peaks.
Ndenotes the number of peaks andDcorresponds to the number of dimensions inimage.
See also
Notes
The peak local maximum function returns the coordinates of local peaks (maxima) in an image. Internally, a maximum filter is used for finding local maxima. This operation dilates the original image. After comparison of the dilated and original images, this function returns the coordinates of the peaks where the dilated image equals the original image.
Examples
>>> import _skimage2 as ski2 >>> image = np.array( ... [[1, 0, 0, 0, 0, 0, 0], ... [0, 0, 0, 0, 0, 0, 0], ... [0, 0, 0, 0, 1, 0, 0], ... [0, 0, 3, 0, 2, 0, 0], ... [0, 0, 2, 0, 0, 0, 0], ... [0, 0, 0, 0, 0, 0, 0]] ... )
Find all peaks
>>> ski2.feature.peak_local_max(image) array([[3, 2], [3, 4]])
Ensure peaks are at least 2 pixels apart
>>> ski2.feature.peak_local_max(image, min_distance=2) array([[3, 2]])
Allow peaks on the image border
>>> ski2.feature.peak_local_max(image, exclude_border=0) array([[3, 2], [3, 4], [0, 0]])