Basic contour detection algorithm