Matlab code for contour detection through dynamic programming