15,795,331 members
See more:
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

# 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)```
Posted
Updated 25-Jan-23 5:50am

## Solution 1

See Solid Geometry[^] for the different formulae to apply to solid shapes.

Member 15201926 26-Jan-23 3:21am
Can I get code in python for the above question
Richard MacCutchan 26-Jan-23 4:17am
No, you are expected to write it. When you hve specific problems then people here will try to help you, but this site is not here to do your work.