I apologize if I am posting in the wrong location. Please let me know if that is the case. Otherwise, I appreciate any help or direction given.
I have an image of an object against a backdrop that I would like to pre-process to only have the region-of-interest. I've got some preprocessing done such as cropping and contrast-enhancing it, but now I want to set the backdrop to a solid color. I'm using canny to generate the contour line between the edge of the object and background as such:
Now, I am wondering if I can somehow use that long line in the middle as a boundary for a mask that will cover everything below said line. Every example I've seen on this site and elsewhere always uses Canny contours that are closed geometric shapes (such as squares, circles, etc.)
What I have tried to is grab the contour with the largest area (hoping that it would capture either the top or bottom half) as such:
cnts = cv2.findContours(img_edge_top.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:10]
contour = max(cnts, key = cv2.contourArea)
cv2.drawContours(img_blur_top, [contour], -1, (0, 255, 0), 3)
cv2.imshow("contour", img_edge_top)
cv2.waitKey(0)
What I get below is the original image:
A point in the right direction or similar example would be enough. Thank you