
- Mahotas - Home
- Mahotas - Introduction
- Mahotas - Computer Vision
- Mahotas - History
- Mahotas - Features
- Mahotas - Installation
- Mahotas Handling Images
- Mahotas - Handling Images
- Mahotas - Loading an Image
- Mahotas - Loading Image as Grey
- Mahotas - Displaying an Image
- Mahotas - Displaying Shape of an Image
- Mahotas - Saving an Image
- Mahotas - Centre of Mass of an Image
- Mahotas - Convolution of Image
- Mahotas - Creating RGB Image
- Mahotas - Euler Number of an Image
- Mahotas - Fraction of Zeros in an Image
- Mahotas - Getting Image Moments
- Mahotas - Local Maxima in an Image
- Mahotas - Image Ellipse Axes
- Mahotas - Image Stretch RGB
- Mahotas Color-Space Conversion
- Mahotas - Color-Space Conversion
- Mahotas - RGB to Gray Conversion
- Mahotas - RGB to LAB Conversion
- Mahotas - RGB to Sepia
- Mahotas - RGB to XYZ Conversion
- Mahotas - XYZ to LAB Conversion
- Mahotas - XYZ to RGB Conversion
- Mahotas - Increase Gamma Correction
- Mahotas - Stretching Gamma Correction
- Mahotas Labeled Image Functions
- Mahotas - Labeled Image Functions
- Mahotas - Labeling Images
- Mahotas - Filtering Regions
- Mahotas - Border Pixels
- Mahotas - Morphological Operations
- Mahotas - Morphological Operators
- Mahotas - Finding Image Mean
- Mahotas - Cropping an Image
- Mahotas - Eccentricity of an Image
- Mahotas - Overlaying Image
- Mahotas - Roundness of Image
- Mahotas - Resizing an Image
- Mahotas - Histogram of Image
- Mahotas - Dilating an Image
- Mahotas - Eroding Image
- Mahotas - Watershed
- Mahotas - Opening Process on Image
- Mahotas - Closing Process on Image
- Mahotas - Closing Holes in an Image
- Mahotas - Conditional Dilating Image
- Mahotas - Conditional Eroding Image
- Mahotas - Conditional Watershed of Image
- Mahotas - Local Minima in Image
- Mahotas - Regional Maxima of Image
- Mahotas - Regional Minima of Image
- Mahotas - Advanced Concepts
- Mahotas - Image Thresholding
- Mahotas - Setting Threshold
- Mahotas - Soft Threshold
- Mahotas - Bernsen Local Thresholding
- Mahotas - Wavelet Transforms
- Making Image Wavelet Center
- Mahotas - Distance Transform
- Mahotas - Polygon Utilities
- Mahotas - Local Binary Patterns
- Threshold Adjacency Statistics
- Mahotas - Haralic Features
- Weight of Labeled Region
- Mahotas - Zernike Features
- Mahotas - Zernike Moments
- Mahotas - Rank Filter
- Mahotas - 2D Laplacian Filter
- Mahotas - Majority Filter
- Mahotas - Mean Filter
- Mahotas - Median Filter
- Mahotas - Otsu's Method
- Mahotas - Gaussian Filtering
- Mahotas - Hit & Miss Transform
- Mahotas - Labeled Max Array
- Mahotas - Mean Value of Image
- Mahotas - SURF Dense Points
- Mahotas - SURF Integral
- Mahotas - Haar Transform
- Highlighting Image Maxima
- Computing Linear Binary Patterns
- Getting Border of Labels
- Reversing Haar Transform
- Riddler-Calvard Method
- Sizes of Labelled Region
- Mahotas - Template Matching
- Speeded-Up Robust Features
- Removing Bordered Labelled
- Mahotas - Daubechies Wavelet
- Mahotas - Sobel Edge Detection
Mahotas - Local Maxima in an Image
A local maximum is a pixel or a particular region in an image that has a higher intensity or value than its neighboring pixels or regions. It represents a peak or a high point in the image data.
One way to find local maxima is by performing a local neighborhood analysis. For each pixel in the image, its neighborhood is examined, and if the pixel is the maximum within its neighborhood, it is considered a local maximum.
Local Maxima in an Image in Mahotas
We can find the local maxima in an image in Mahotas using the locmax() function. It takes an image as input and returns a binary mask where the local maxima are marked as True or 1.
The local_maxima() function in Mahotas uses a non-maximum suppression algorithm to locate the local maxima efficiently. By examining each pixel and its neighborhood, the function determines whether the pixel is the maximum within its local region.
This analysis allows for the detection of peaks or high points in the image data, which can play an important role for various applications such as feature extraction, object detection, and image segmentation.
The non−maximum suppression algorithm is used in object detection and edge detection tasks to eliminate redundant and weak detections by selecting the highest intensity or response value among neighboring pixels, thereby keeping only the local maxima and suppressing non−maximum values.
Using the locmax() Function
The locmax() function in Mahotas is used to identify local maxima in an input image efficiently. It takes a grayscale or single channel image as input and returns a binary mask where the local maxima are marked as True or 1.
Syntax
Following is the basic syntax of the locmax() function in mahotas −
mahotas.Locmax(image_name)
where, 'image_name' is the input image.
Example
Following is the basic example to find the local maxima in an image −
import mahotas as mh import numpy as np from pylab import imshow, show import matplotlib.pyplot as plt image = mh.imread('nature.jpeg', as_grey=True) maxima = mh.locmax(image) print("Maxima:", maxima) imshow(maxima) show()
Output
Following is the output of the above code −
Maxima: [[ True True True ... True True True] [ True True True ... True True True] [ True True True ... True True True] ... [False False False ... False False False] [False False False ... False False True] [ True False True ... False False True]]
The image displayed is as shown below −

Using the regmax() Function
We can also use the regmax() function in Mahotas for finding regional maxima in an image. A regional maximum is defined as a point in the image that has a higher intensity value than all of its neighboring pixels within a specified region.
The regmax() function accepts an image as the input parameter and returns a boolean image of the same size as an input image.
Following is the basic syntax of regmax function in mahotas −
regmax(image)
where, 'image' is a grayscale or color image on which regional maxima need to be identified.
Example
In here, we are trying to find the regional maxima within the connected regions in a grayscale image using the regmax() function −
import mahotas as mh def find_local_maxima(image): regional_maxima = mh.regmax(image) return regional_maxima image = mh.imread('sun.png', as_grey=True) local_maxima_points = find_local_maxima(image) print(local_maxima_points)
Output
Output of the above code is as follows −
[[False False False ... False False False] [False False False ... False False False] [False False False ... False False False] ... [False False False ... False False False] [False False False ... False False False] [False False False ... True False False]]
Regional Maxima of a Colored Image
We can also find the regional maxima within the connected regions in a color image using the regmax() function.
Example
Now, we are trying to find the regional maxima within the connected regions in a color image using the regmax() function −
import mahotas as mh def find_local_maxima(image): regional_maxima = mh.regmax(image) return regional_maxima image = mh.imread('tree.tiff') local_maxima_points = find_local_maxima(image) print(local_maxima_points)
Output
We get the output as follows −
[[[False False False] [ True True True] [False False False] ... [False False False] [False False False] [False False False]] . . . [False False False] [False False False] [ True False False]]]