![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 - Roundness of Image
The roundness of an image refers to the measure of how closely an object or a region in the image resembles a perfect circle. It is a metric used to quantify the degree of circularity or deviation from circularity.
The roundness value is calculated by comparing the object's shape to that of a circle.
A perfectly round object would have a roundness value close to 1, while objects that are more elongated or irregular in shape would have roundness values closer to 0.
Roundness of Image in Mahotas
In Mahotas, we can calculate the roundness of an object using the mahotas.features.roundness() function. This function takes a binary image as input.
A binary image is an image where each pixel is either classified as foreground (object of interest) or background. Generally, the foreground pixels are represented by white (pixel value = 1), and the background pixels are represented by black (pixel value = 0).
The input binary image should be in a boolean format or represented as a NumPy array with boolean values.
The mahotas.features.roundness() function
The 'mahotas.features.roundness()' function accepts a binary image as input and returns a float value between 0 and 1. The closer the value is to 1.0, the closer the shape is to a perfect circle.
Syntax
Following is the basic syntax of the roundness() function in mahotas −
mahotas.features.roundness(image)
Where, 'image' is the Boolean image input.
Example
In the following example, we are finding the roundness of an image using the roundness() function −
import mahotas as mh import numpy as np image = mh.imread('sun.png', as_grey = True) roundness = mh.features.roundness(image) print("Roundness of the image= ", roundness)
Output
The output obtained is as follows −
Roundness of the image= 4.98542867728303e-05
Blob Roundness in Binary Image
Blob roundness refers to a measure of how closely a blob resembles a perfect circle. A roundness value close to 1 indicates a more circular blob, while a value significantly lower than 1 indicates a more elongated or irregular shape.
To compute blob roundness in a binary image using Mahotas, we need to take an image having a clear separation between the foreground (blobs) and the background. Then, label the blobs in the binary image to assign a unique identifier (index) to each blob.
It helps in distinguishing individual blobs. Thereafter, compute the roundness of each labeled blob.
Example
In here, we are trying to compute the blob roundness in a binary image −
import mahotas as mh import numpy as np image = mh.imread(tree.tiff', as_grey=True) # Labelling the blobs in the image labeled, _ = mh.label(image) # Computing the roundness of each blob roundness = mh.features.roundness(labeled) print("Blob Roundness:", roundness)
Output
Output of the above code is as follows −
Blob Roundness: 2.0659091361803767
Using zernike_moment
Zernike moments are mathematical representations of the shape of an object in an image.
It captures the roundness and other shape attributes of an image by analyzing the distribution of intensity or color variations within the object.
To determine the roundness of an image using Zernike Moments, we start by specifying a radius value. This radius determines the size of the circular region in which the moments will be computed.
Choosing a smaller radius is ideal for analyzing smaller objects, while a larger radius is more suitable for larger objects.
Once we have the Zernike Moments calculated, the first moment becomes particularly important when assessing image roundness. It serves as a representative measure of the overall roundness of the object within the image.
By extracting the first element from the Zernike Moments list, we obtain a specific value that quantifies the roundness of the object accurately.
Example
Here, we are trying to find an image roundness with Zernike Moments −
import mahotas as mh image = mh.imread('nature.jpeg', as_grey = True) # Setting the radius for calculating Zernike moments radius = 10 # Calculating the Zernike moments moments = mh.features.zernike_moments(image, radius=radius) # The first Zernike moment represents roundness roundness = moments[0] print(roundness)
Output
After executing the above code, we get the output as shown below −
0.3183098861837907