Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to clip an image by extreme points?

Hello, I have found the contours of the object in the image with a cv2.findContours and I want to clip the image in the extreme points. However, the image returned is not correct.

Below is the code, I have implemented. Any hint?

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)
    cnt = contours[0]
    xmin = min(tuple(cnt[cnt[:, :, 0].argmin()][0]))
    ymin = min(tuple(cnt[cnt[:, :, 1].argmin()][0]))
    xmax = max(tuple(cnt[cnt[:, :, 0].argmax()][0]))
    ymax = max(tuple(cnt[cnt[:, :, 1].argmax()][0]))

    clipped = segmented[xmin:xmax, ymin:ymax]

    return clipped

Thank you