I am trying to remove the image that is not contoured. Are there any suggestions on how to achieve them? Below is my code for the contour
import numpy as np
import cv2
im = cv2.imread('after.png')
imgray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(imgray, 127, 255, 0)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
largest_area = sorted(contours, key=cv2.contourArea)[-1]
mask = np.zeros(im.shape, np.uint8)
cv2.drawContours(im, contours, -1, (0, 255, 0), 3)
cv2.drawContours(imgray, contours, -1, (0, 255, 0), 3)
image_remainder = cv2.bitwise_and(im, 255 - mask)
#cv2.imshow('Image', im)
cv2.imshow('Image GRAY', imgray)
cv2.imshow('extract', image_remainder)
#cv2.imwrite("remainder.png", image_remainder)
cv2.waitKey(0)
cv2.destroyAllWindows()
Is there a way to only get the skin inside the contour, hope you can help. Thank you in advance.