bundles / skimage latest / skimage / morphology / extrema / local_maxima
function
skimage.morphology.extrema:local_maxima
source: /dev/scikit-image/src/skimage/morphology/extrema.py :275
Signature
def local_maxima ( image , footprint = None , connectivity = None , indices = False , allow_borders = True ) Summary
Find local maxima of n-dimensional array.
Extended Summary
The local maxima are defined as connected sets of pixels with equal gray level (plateaus) strictly greater than the gray levels of all pixels in the neighborhood.
Parameters
image: ndarrayAn n-dimensional array.
footprint: ndarray, optionalThe footprint (structuring element) used to determine the neighborhood of each evaluated pixel (
Truedenotes a connected pixel). It must be a boolean array and have the same number of dimensions asimage. If neitherfootprintnorconnectivityare given, all adjacent pixels are considered as part of the neighborhood.connectivity: int, optionalA number used to determine the neighborhood of each evaluated pixel. Adjacent pixels whose squared distance from the center is less than or equal to
connectivityare considered neighbors. Ignored iffootprintis not None.indices: bool, optionalIf True, the output will be a tuple of one-dimensional arrays representing the indices of local maxima in each dimension. If False, the output will be a boolean array with the same shape as
image.allow_borders: bool, optionalIf true, plateaus that touch the image border are valid maxima.
Returns
maxima: ndarray or tuple[ndarray]If
indicesis false, a boolean array with the same shape asimageis returned withTrueindicating the position of local maxima (Falseotherwise). Ifindicesis true, a tuple of one-dimensional arrays containing the coordinates (indices) of all found maxima.
Warns
: UserWarningIf
allow_bordersis false and any dimension of the givenimageis shorter than 3 samples, maxima can't exist and a warning is shown.
Notes
This function operates on the following ideas:
Make a first pass over the image's last dimension and flag candidates for local maxima by comparing pixels in only one direction. If the pixels aren't connected in the last dimension all pixels are flagged as candidates instead.
For each candidate:
Perform a flood-fill to find all connected pixels that have the same gray value and are part of the plateau.
Consider the connected neighborhood of a plateau: if no bordering sample has a higher gray level, mark the plateau as a definite local maximum.
Examples
from skimage.morphology import local_maxima image = np.zeros((4, 7), dtype=int) image[1:3, 1:3] = 1 image[3, 0] = 1 image[1:3, 4:6] = 2 image[3, 6] = 3 image✓
local_maxima(image) local_maxima(image, indices=True)✓
local_maxima(image, connectivity=1)
✓local_maxima(image, connectivity=1, allow_borders=False)
✓See also
Aliases
-
skimage.morphology.local_maxima