Module: feature.peak

skimage.feature.peak.peak_local_max(image[, ...]) Find peaks in an image, and return them as coordinates or a boolean array.

peak_local_max

skimage.feature.peak.peak_local_max(image, min_distance=10, threshold_abs=0, threshold_rel=0.1, exclude_border=True, indices=True, num_peaks=inf, footprint=None, labels=None)

Find peaks in an image, and return them as coordinates or a boolean array.

Peaks are the local maxima in a region of 2 * min_distance + 1 (i.e. peaks are separated by at least min_distance).

NOTE: If peaks are flat (i.e. multiple adjacent pixels have identical intensities), the coordinates of all such pixels are returned.

Parameters :

image : ndarray of floats

Input image.

min_distance : int

Minimum number of pixels separating peaks in a region of 2 * min_distance + 1 (i.e. peaks are separated by at least min_distance). If exclude_border is True, this value also excludes a border min_distance from the image boundary. To find the maximum number of peaks, use min_distance=1.

threshold_abs : float

Minimum intensity of peaks.

threshold_rel : float

Minimum intensity of peaks calculated as max(image) * threshold_rel.

exclude_border : bool

If True, min_distance excludes peaks from the border of the image as well as from each other.

indices : bool

If True, the output will be a matrix representing peak coordinates. If False, the output will be a boolean matrix shaped as image.shape with peaks present at True elements.

num_peaks : int

Maximum number of peaks. When the number of peaks exceeds num_peaks, return num_peaks peaks based on highest peak intensity.

footprint : ndarray of bools, optional

If provided, footprint == 1 represents the local region within which to search for peaks at every point in image. Overrides min_distance, except for border exclusion if exclude_border=True.

labels : ndarray of ints, optional

If provided, each unique region labels == value represents a unique region to search for peaks. Zero is reserved for background.

Returns :

output : (N, 2) array or ndarray of bools

  • If indices = True : (row, column) coordinates of peaks.
  • If indices = False : Boolean array shaped like image, with peaks represented by True values.

Notes

The peak local maximum function returns the coordinates of local peaks (maxima) in a image. A maximum filter is used for finding local maxima. This operation dilates the original image. After comparison between dilated and original image, peak_local_max function returns the coordinates of peaks where dilated image = original.

Examples

>>> im = np.zeros((7, 7))
>>> im[3, 4] = 1
>>> im[3, 2] = 1.5
>>> im
array([[ 0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ],
       [ 0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ],
       [ 0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ],
       [ 0. ,  0. ,  1.5,  0. ,  1. ,  0. ,  0. ],
       [ 0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ],
       [ 0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ],
       [ 0. ,  0. ,  0. ,  0. ,  0. ,  0. ,  0. ]])
>>> peak_local_max(im, min_distance=1)
array([[3, 2],
       [3, 4]])
>>> peak_local_max(im, min_distance=2)
array([[3, 2]])