![Mahotas](/mahotas/images/mahotas-mini-logo.jpg)
- Mahotas Tutorial
- 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 - Highlighting Image Maxima
Highlighting image maxima refers to displaying the brightest areas of an image. Image maxima, also known as regional maxima, is the area having the highest pixel intensity value amongst all other areas of an image.
The image maxima consider the entire image when searching for the brightest areas. An image can have multiple regional maxima, but all of them will have the same level of brightness. This is because only the brightest value is considered as the image maxima.
Highlighting Image Maxima in Mahotas
In Mahotas, we can use the mahotas.regmax() function to highlight maxima in an image. Image maxima represent high intensity regions; hence they are identified by looking at an image's intensity peaks. Following is the basic approach used by the function to highlight the image maxima −
First, it compares the intensity value of each local maxima region to its neighbors.
If a brighter neighbor is found, the function sets it to be the new image maxima.
This process continues until all the regions have been compared to the image maxima.
The mahotas.regmax() function
The mahotas.regmax() function takes a grayscale image as input. It returns an image where the 1s represent the image maxima points, while the 0s represent normal points.
Syntax
Following is the basic syntax of the regmax() function in mahotas −
mahotas.regmax(f, Bc={3x3 cross}, out={np.empty(f.shape, bool)})
Where,
f − It is the input grayscale image.
Bc (optional) − It is the structuring element used for connectivity.
out(optional) − It is the output array of Boolean data type (defaults to new array of same size as f).
Example
In the following example, we are highlighting image maxima using the mh.regmax() function.
import mahotas as mh import numpy as np import matplotlib.pyplot as mtplt # Loading the image image = mh.imread('sun.png') # Converting it to grayscale image = mh.colors.rgb2gray(image) # Getting the regional maxima regional_maxima = mh.regmax(image) # Creating a figure and axes for subplots fig, axes = mtplt.subplots(1, 2) # Displaying the original image axes[0].imshow(image, cmap='gray') axes[0].set_title('Original Image') axes[0].set_axis_off() # Displaying the highlighted image maxima axes[1].imshow(regional_maxima, cmap='gray') axes[1].set_title('Regional Maxima') axes[1].set_axis_off() # Adjusting spacing between subplots mtplt.tight_layout() # Showing the figures mtplt.show()
Output
Following is the output of the above code −
![Image Maxima](/mahotas/images/image_maxima.jpg)
Highlighting Maxima by using custom Structuring Element
We can also highlight the image maxima by using a custom structuring element. A structuring element is an array consisting of only ones and zeroes. It defines the connectivity pattern of the neighborhood pixels.
Pixels with the value 1 are included in connectivity analysis while the pixels with the value 0 are excluded.
In mahotas, we create a custom structuring element using the mh.disk() function. Then, we set this custom structuring element as the Bc parameter in the regmax() function to highlight the image maxima.
Example
In this example, we are highlighting the image maxima by using a custom structuring element.
import mahotas as mh import numpy as np import matplotlib.pyplot as mtplt # Loading the image image = mh.imread('tree.tiff') # Converting it to grayscale image = mh.colors.rgb2gray(image) # Creating a custom structuring element se = np.array([[0, 1, 0],[1, 1, 1],[0, 1, 0]]) # Getting the regional maxima regional_maxima = mh.regmax(image, Bc=se) # Creating a figure and axes for subplots fig, axes = mtplt.subplots(1, 2) # Displaying the original image axes[0].imshow(image, cmap='gray') axes[0].set_title('Original Image') axes[0].set_axis_off() # Displaying the highlighted image maxima axes[1].imshow(regional_maxima, cmap='gray') axes[1].set_title('Regional Maxima') axes[1].set_axis_off() # Adjusting spacing between subplots mtplt.tight_layout() # Showing the figures mtplt.show()
Output
After executing the above code, we get the following output −
![Image Maxima1](/mahotas/images/image_maxima1.jpg)