
- Scikit Image – Introduction
- Scikit Image - Image Processing
- Scikit Image - Numpy Images
- Scikit Image - Image datatypes
- Scikit Image - Using Plugins
- Scikit Image - Image Handlings
- Scikit Image - Reading Images
- Scikit Image - Writing Images
- Scikit Image - Displaying Images
- Scikit Image - Image Collections
- Scikit Image - Image Stack
- Scikit Image - Multi Image
- Scikit Image - Data Visualization
- Scikit Image - Using Matplotlib
- Scikit Image - Using Ploty
- Scikit Image - Using Mayavi
- Scikit Image - Using Napari
- Scikit Image - Color Manipulation
- Scikit Image - Alpha Channel
- Scikit Image - Conversion b/w Color & Gray Values
- Scikit Image - Conversion b/w RGB & HSV
- Scikit Image - Conversion to CIE-LAB Color Space
- Scikit Image - Conversion from CIE-LAB Color Space
- Scikit Image - Conversion to luv Color Space
- Scikit Image - Conversion from luv Color Space
- Scikit Image - Image Inversion
- Scikit Image - Painting Images with Labels
- Scikit Image - Contrast & Exposure
- Scikit Image - Contrast
- Scikit Image - Contrast enhancement
- Scikit Image - Exposure
- Scikit Image - Histogram Matching
- Scikit Image - Histogram Equalization
- Scikit Image - Local Histogram Equalization
- Scikit Image - Tinting gray-scale images
- Scikit Image - Image Transformation
- Scikit Image - Scaling an image
- Scikit Image - Rotating an Image
- Scikit Image - Warping an Image
- Scikit Image - Affine Transform
- Scikit Image - Piecewise Affine Transform
- Scikit Image - ProjectiveTransform
- Scikit Image - EuclideanTransform
- Scikit Image - Radon Transform
- Scikit Image - Line Hough Transform
- Scikit Image - Probabilistic Hough Transform
- Scikit Image - Circular Hough Transforms
- Scikit Image - Elliptical Hough Transforms
- Scikit Image - Polynomial Transform
- Scikit Image - Image Pyramids
- Scikit Image - Pyramid Gaussian Transform
- Scikit Image - Pyramid Laplacian Transform
- Scikit Image - Swirl Transform
- Scikit Image - Morphological Operations
- Scikit Image - Erosion
- Scikit Image - Dilation
- Scikit Image - Black & White Tophat Morphologies
- Scikit Image - Convex Hull
- Scikit Image - Generating footprints
- Scikit Image - Isotopic Dilation & Erosion
- Scikit Image - Isotopic Closing & Opening of an Image
- Scikit Image - Skelitonizing an Image
- Scikit Image - Morphological Thinning
- Scikit Image - Masking an image
- Scikit Image - Area Closing & Opening of an Image
- Scikit Image - Diameter Closing & Opening of an Image
- Scikit Image - Morphological reconstruction of an Image
- Scikit Image - Finding local Maxima
- Scikit Image - Finding local Minima
- Scikit Image - Removing Small Holes from an Image
- Scikit Image - Removing Small Objects from an Image
- Scikit Image - Filters
- Scikit Image - Image Filters
- Scikit Image - Median Filter
- Scikit Image - Mean Filters
- Scikit Image - Morphological gray-level Filters
- Scikit Image - Gabor Filter
- Scikit Image - Gaussian Filter
- Scikit Image - Butterworth Filter
- Scikit Image - Frangi Filter
- Scikit Image - Hessian Filter
- Scikit Image - Meijering Neuriteness Filter
- Scikit Image - Sato Filter
- Scikit Image - Sobel Filter
- Scikit Image - Farid Filter
- Scikit Image - Scharr Filter
- Scikit Image - Unsharp Mask Filter
- Scikit Image - Roberts Cross Operator
- Scikit Image - Lapalace Operator
- Scikit Image - Window Functions With Images
- Scikit Image - Thresholding
- Scikit Image - Applying Threshold
- Scikit Image - Otsu Thresholding
- Scikit Image - Local thresholding
- Scikit Image - Hysteresis Thresholding
- Scikit Image - Li thresholding
- Scikit Image - Multi-Otsu Thresholding
- Scikit Image - Niblack and Sauvola Thresholding
- Scikit Image - Restoring Images
- Scikit Image - Rolling-ball Algorithm
- Scikit Image - Denoising an Image
- Scikit Image - Wavelet Denoising
- Scikit Image - Non-local means denoising for preserving textures
- Scikit Image - Calibrating Denoisers Using J-Invariance
- Scikit Image - Total Variation Denoising
- Scikit Image - Shift-invariant wavelet denoising
- Scikit Image - Image Deconvolution
- Scikit Image - Richardson-Lucy Deconvolution
- Scikit Image - Recover the original from a wrapped phase image
- Scikit Image - Image Inpainting
- Scikit Image - Registering Images
- Scikit Image - Image Registration
- Scikit Image - Masked Normalized Cross-Correlation
- Scikit Image - Registration using optical flow
- Scikit Image - Assemble images with simple image stitching
- Scikit Image - Registration using Polar and Log-Polar
- Scikit Image - Feature Detection
- Scikit Image - Dense DAISY Feature Description
- Scikit Image - Histogram of Oriented Gradients
- Scikit Image - Template Matching
- Scikit Image - CENSURE Feature Detector
- Scikit Image - BRIEF Binary Descriptor
- Scikit Image - SIFT Feature Detector and Descriptor Extractor
- Scikit Image - GLCM Texture Features
- Scikit Image - Shape Index
- Scikit Image - Sliding Window Histogram
- Scikit Image - Finding Contour
- Scikit Image - Texture Classification Using Local Binary Pattern
- Scikit Image - Texture Classification Using Multi-Block Local Binary Pattern
- Scikit Image - Active Contour Model
- Scikit Image - Canny Edge Detection
- Scikit Image - Marching Cubes
- Scikit Image - Foerstner Corner Detection
- Scikit Image - Harris Corner Detection
- Scikit Image - Extracting FAST Corners
- Scikit Image - Shi-Tomasi Corner Detection
- Scikit Image - Haar Like Feature Detection
- Scikit Image - Haar Feature detection of coordinates
- Scikit Image - Hessian matrix
- Scikit Image - ORB feature Detection
- Scikit Image - Additional Concepts
- Scikit Image - Render text onto an image
- Scikit Image - Face detection using a cascade classifier
- Scikit Image - Face classification using Haar-like feature descriptor
- Scikit Image - Visual image comparison
- Scikit Image - Exploring Region Properties With Pandas
Scikit Image - Finding Local Maxima
In image processing, a maxima or maximum refers to the points or regions in a digital image where the pixel values are at their highest within a specific neighborhood. In contrast, finding maxima in an image involves identifying points or regions where the values are at their highest within a local neighborhood. Local maxima are significant peaks or high-intensity areas within the data. Finding maxima plays a significant role in various image analysis tasks, such as feature detection, object segmentation, and image enhancement.
The scikit image libraries provide functions like local_maxima() and h_maxima to find the local maxima in an image.
Using the skimage.morphology.local_maxima() function
The local_maxima() function is used to find local maxima in an n-dimensional array (image). Local maxima are defined as connected sets of pixels with equal gray levels (plateaus) that are strictly greater than the gray levels of all pixels in their neighborhood.
Syntax
Following is the syntax of this function −
skimage.morphology.local_maxima(image, footprint=None, connectivity=None, indices=False, allow_borders=True)
Parameters
- image (ndarray): This is the n-dimensional array on which local maxima will be calculated.
- footprint (ndarray, optional): The footprint, also known as the structuring element, is used to determine the neighborhood of each evaluated pixel. It must be a boolean array and have the same number of dimensions as the image. If neither footprint nor connectivity are given, all adjacent pixels are considered as part of the neighborhood.
- connectivity (int, optional): This parameter is used to determine the neighborhood of each evaluated pixel. It specifies how pixels are considered neighbors. Pixels whose squared distance from the center is less than or equal to connectivity are considered neighbors. This parameter is ignored if the footprint is not None.
- indices (bool, optional): If True, the output will be a tuple of one-dimensional arrays representing the indices (coordinates) of local maxima in each dimension. If False, the output will be a boolean array with the same shape as the image, where True indicates the position of local maxima, and False indicates other positions.
- allow_borders (bool, optional): If True, it allows plateaus that touch the image border to be considered as valid maxima. If set to False, maxima that are on the image borders are not considered.
Return Value
It returns returns maxima, which can be either an ndarray or a tuple of ndarrays, depending on the value of the indices parameter.
Example
The following example demonstrates how to use the local_maxima() function to find local maxima in a grayscale image.
import numpy as np from skimage.morphology import local_maxima from skimage.measure import label import matplotlib.pyplot as plt from skimage import io, color, exposure # Load the input image image = io.imread('Images/Tajmahal.jpg') # For illustration purposes, we focus on a specific region of the image. x_0 = 170 y_0 = 100 width = 250 height = 150 # Crop the image to the specified region image = color.rgb2gray(image)[y_0:(y_0 + height), x_0:(x_0 + width)] # Rescale the image intensity for visualization purposes. image = exposure.rescale_intensity(image) # Find local maxima by comparing to all neighboring pixels (maximal connectivity) maxima1 = local_maxima(image) # Label the local maxima to distinguish them label_maxima1 = label(maxima1) # Overlay the labeled local maxima on the original image overlay = color.label2rgb(label_maxima1, image, alpha=0.7, bg_label=0, bg_color=None, colors=[(1, 0, 0)]) # Plot the original image and the results fig, axes = plt.subplots(1, 2, figsize=(10, 5)) ax = axes.ravel() # Display the original binary image ax[0].imshow(image, cmap=plt.cm.gray) ax[0].axis('off') ax[0].set_title('Original Image') # Display the Thinned image ax[1].imshow(overlay, cmap=plt.cm.gray) ax[1].axis('off') ax[1].set_title('Local Maxima (Maximal Connectivity)') plt.tight_layout() plt.show()
Output
On executing the above program, you will get the following output −

In this image, you can notice that there were numerous local maxima, often arising from image noise. To address this, the h_maxima() function can be used to find local maxima while considering a minimum height requirement, denoted as "h." This 'h' value represents the difference in gray levels that must be descended from a point to reach a higher maximum and serves as a measure of local contrast.
Using the skimage.morphology.h_maxima() function
The h_maxima() function is used to find all maxima in an image that have a specified minimum height threshold (h). These local maxima are connected sets of pixels with gray levels strictly greater than the gray level of all pixels in their direct neighbourhood.
A local maximum M with a height of h is defined as a point where there exists at least one path connecting M to another local maximum that is either equal to or higher in value. Along this path, the minimum value should not decrease by more than h compared to the value at M. Additionally, there should be no path to any other equal or higher local maximum where the minimal value along that path is greater than M's value minus h. The global maxima of the image are also found by this function.
Syntax
Following is the syntax of this function −
skimage.morphology.h_maxima(image, h, footprint=None)
Parameters
- image (ndarray): This is the input image on which maxima will be calculated.
- h (unsigned integer): h is the minimal height threshold. Only maxima with a height (intensity difference) greater than or equal to h will be considered valid maxima.
- footprint (ndarray, optional): This parameter specifies the neighborhood around each pixel that will be considered when determining if a pixel is a maximum. The neighborhood is expressed as an n-dimensional array of 1s and 0s. By default, it uses a neighborhood that corresponds to a 3x3 square for 2D images and a 3x3x3 cube for 3D images, following the maximum norm.
Return Value
It returns h_max, which is an ndarray representing the local maxima of height greater than or equal to h, including the global maxima. The resulting image is binary, where pixels belonging to the determined maxima are set to 1, and others are set to 0.
Example
The following example demonstrates how to identify maxima (peaks) in a specific region of an image using the h-maxima() function.
import numpy as np from skimage.morphology import h_maxima from skimage.measure import label import matplotlib.pyplot as plt from skimage import io, color, exposure # Load the input image image = io.imread('Images/Tajmahal.jpg') # For illustration purposes, we focus on a specific region of the image. x_0 = 170 y_0 = 100 width = 250 height = 150 # Crop the image to the specified region image = color.rgb2gray(image)[y_0:(y_0 + height), x_0:(x_0 + width)] # Rescale the image intensity for visualization purposes image = exposure.rescale_intensity(image) # Set the h parameter for h_maxima h = 0.05 # Find h-maxima in the cropped and rescaled image h_maxima_image = h_maxima(image, h) # Label the h-maxima to distinguish them labeled_h_maxima = label(h_maxima_image) # Overlay the labeled h-maxima on the original image overlay = color.label2rgb(labeled_h_maxima, image, alpha=0.7, bg_label=0, bg_color=None, colors=[(1, 0, 0)]) # Create subplots for displaying the original image and h-maxima fig, axes = plt.subplots(1, 2, figsize=(10, 5)) ax = axes.ravel() # Display the original image ax[0].imshow(image, cmap=plt.cm.gray) ax[0].axis('off') ax[0].set_title('Original Image') # Display the h-maxima overlay ax[1].imshow(overlay, cmap=plt.cm.gray) ax[1].axis('off') ax[1].set_title('h-Maxima (h={})'.format(h)) plt.tight_layout() plt.show()
Output
On executing the above program, you will get the following output −
