
- 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 - Eccentricity of an Image
The eccentricity of an image refers to the measure of how elongated or stretched the shape of an object or region within the image is. It provides a quantitative measure of how how much the shape deviates from a perfect circle.
The eccentricity value ranges between 0 and 1, where −
0 − Indicates a perfect circle. Objects with an eccentricity of 0 have the least elongation and are perfectly symmetric.
Close to 1 − Indicates increasingly elongated shapes. As the eccentricity value approaches 1, the shapes become more elongated and less circular.
Eccentricity of an Image in Mahotas
We can calculate the eccentricity of an image in Mahotas using the 'mahotas.features.eccentricity()' function.
If the eccentricity value is higher, it indicates that the shapes in the image are more stretched or elongated. On the other hand, if the eccentricity value is lower, it indicates that the shapes are closer to being perfect circles or less elongated.
The mahotas.features.eccentricity() function
The eccentricity() function in mahotas helps us measure how stretched or elongated the shapes are in an image. This function takes an image with single channel as input and returns a float point number between 0 and 1.
Syntax
Following is the basic syntax of the eccentricity() function in mahotas −
mahotas.features.eccentricity(bwimage)
Where, 'bwimage' is the input image interpreted as a boolean value.
Example
In the following example, we are finding the eccentricity of an image −
import mahotas as mh import numpy as np from pylab import imshow, show image = mh.imread('nature.jpeg', as_grey = True) eccentricity= mh.features.eccentricity(image) print("Eccentricity of the image =", eccentricity)
Output
Output of the above code is as follows −
Eccentricity of the image = 0.8902515127811386
Calculating Eccentricity using Binary Image
To convert a grayscale image into a binary format, we use a technique called thresholding. This process helps us to separate the image into two parts − foreground (white) and background (black).
We do this by picking a threshold value (indicates pixel intensity), which acts as a cutoff point.
Mahotas simplifies this process for us by providing the ">" operator, which allows us to compare pixel values with the threshold value and create a binary image. With the binary image ready, we can now calculate the eccentricity.
Example
Here, we are trying to calculate the eccentricity of a binary image −
import mahotas as mh image = mh.imread('nature.jpeg', as_grey=True) # Converting image to binary based on a fixed threshold threshold = 128 binary_image = image > threshold # Calculating eccentricity eccentricity = mh.features.eccentricity(binary_image) print("Eccentricity:", eccentricity)
Output
After executing the above code, we get the following output −
Eccentricity: 0.7943319646935899
Calculating Eccentricity using the Skeletonization
Skeletonization, also known as thinning, is a process that aims to reduce the shape or structure of an object, representing it as a thin skeleton. We can achieve this using the thin() function in mahotas.
The mahotas.thin() function takes a binary image as input, where the object of interest is represented by white pixels (pixel value of 1) and the background is represented by black pixels (pixel value of 0).
We can calculate the eccentricity of an image using skeletonization by reducing the image to its skeleton representation.
Example
Now, we are calculating the eccentricity of an image using the skeletonization −
import mahotas as mh import matplotlib.pyplot as plt # Read the image and convert it to grayscale image = mh.imread('tree.tiff') grey_image = mh.colors.rgb2grey(image) # Skeletonizing the image skeleton = mh.thin(grey_image) # Calculating the eccentricity of the skeletonized image eccentricity = mh.features.eccentricity(skeleton) # Printing the eccentricity print(eccentricity) # Create a figure with subplots fig, axes = plt.subplots(1, 2, figsize=(7,5 )) # Display the original image axes[0].imshow(image) axes[0].set_title('Original Image') axes[0].axis('off') # Display the skeletonized image axes[1].imshow(skeleton, cmap='gray') axes[1].set_title('Skeletonized Image') axes[1].axis('off') # Adjust the layout and display the plot plt.tight_layout() plt.show()
Output
The output obtained is as shown below −
0.8975030064719701
The image displayed is as shown below −
