rewrite segmentContour.m