1 | initial version |
I was able to get the expected results changing my code as below:
def clipping_image( image ):
'''
Clip segmented imaged based on the contours of the leaf
'''
image = cv2.cvtColor( image, cv2.COLOR_BGR2GRAY );
segmented, contours, hierarchy = cv2.findContours(image, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
x, y = [], []
for contour_line in contours:
for contour in contour_line:
x.append(contour[0][0])
y.append(contour[0][1])
x1, x2, y1, y2 = min(x), max(x), min(y), max(y)
clipped = segmented[y1:y2, x1:x2]
return clipped