Removing duplicate and enclosed contours