I need to Calculate volume, area, perimeter, major axis, minor axis and eccentricity for binary image of apple, tomato, lemon, orange, guava and gooseberry. So far calculated all I would be getting same value for both volume and area, how to calculate volume?
What I have tried:
import cv2
import pandas as pd
from skimage import measure
# List of binary images
image_list = ["/content/drive/MyDrive/Apple Sample 1/15 1.jpg", "/content/drive/MyDrive/Apple Sample 1/15 2.jpg", "/content/drive/MyDrive/Apple Sample 1/16 1.jpg"]
# Empty list to store extracted features
feature_list = []
# Iterate through the list of images
for image_name in image_list:
# Read in binary image of apple
binary_image = cv2.imread(image_name,0)
# Find contours in the binary image
contours, _ = cv2.findContours(binary_image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
# Extract the first contour
cnt = contours[0]
# Calculate the perimeter of the contour
perimeter = cv2.arcLength(cnt, True)
# Extract region properties of apple
regions = measure.regionprops(binary_image)
# Extract features of interest
for region in regions:
volume = region.area
area = region.area
eccentricity = region.eccentricity
major_axis = region.major_axis_length
minor_axis = region.minor_axis_length
# Create a dictionary with extracted features
feature_dict = {"Volume":volume, "Area": area, "Perimeter": perimeter, "Eccentricity": eccentricity, "Major axis": major_axis, "Minor axis": minor_axis}
# Append the features of each image to the feature_list
feature_list.append(feature_dict)
# Convert the list of dictionaries to a dataframe
df = pd.DataFrame(feature_list)
# Print the dataframe
print(df)