After the graph is constructed, the optimal path is determined by dynamic programming (Sonka et al., 2014). However, the path found by standard dynamic programming does not guarantee a closed contour after reversely mapping onto the original image,since the starting node p1 and ending node pNg on the path are not necessarily on the same row (Fig. 6(a)).To solve this problem, an iterative approach is applied if a dis-continuous boundary is detected, which is determined by |p1−pNg| > t, where t is the tolerance for distance discontinuity and is set as 3 pixels: