modified for contour detection