I'm trying to calculate the pixel ratio of two halves of an image split vertically and horizontally along its centroid. The goal is to see how symmetrical/asymmetrical the image is. Below is the code, the original image, and an image showing what I'm trying to do.
So far, I've thresholded the image, created a contour around its perimeter, filled that contour, and calculated and labeled the centroid.
I'm stuck on how to (a) split the contour into two, and (b) calculate the pixel ratios between the two halves of the contour image (just the black parts. Thanks for any advice and/or help.
# import packages
import argparse
import imutils
import cv2
# construct argument parser
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
help="path to the input image")
args = vars(ap.parse_args())
# load the image
image = cv2.imread(args["image"])
# convert it to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# threshold the image
(T, threshInv) = cv2.threshold(gray, 200, 255, cv2.THRESH_BINARY_INV)
# find outer contour of thresholded image
cnts = cv2.findContours(threshInv.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
# loop over the contour/s for image moments
for c in cnts:
# compute the center of the contour
M = cv2.moments(c)
# calculate the centroid
cX = int(M["m10"] / M["m00"])
cY = int(M["m01"] / M["m00"])
# draw and fill the contour on the image
cv2.drawContours(image, [c], -1, (0, 0, 0), thickness=cv2.FILLED)
# draw the centroid on the filled contour
cv2.circle(image, (cX, cY), 7, (255, 0, 0), -1)
# show the image
cv2.imshow("Image", image)
cv2.waitKey(0)
Original image:
Goal:

