A thinning algorithm based on contours