Image segmentation with specific constraints has found applications in several areas such as biomedical image analysis and data mining. In this paper, we study the problem of simultaneous detection of both borders of a doughnut-shaped and smooth objects in 2-D medical images. Image objects of that shape are often studied in medical applications. We present an O(IJU(U-L)logJUlog(U-L)) time algorithm, where the size of the input 2-D image is I x J, M is the smoothness parameter with 1 = M = J, and L and U are the thickness parameters specifying the thickness between two border contours of a doughnut-shaped object. Previous approaches for solving this segmentation problem are computationally expensive and/or need a lot of user interference. Our algorithm improves the straightforward dynamic programming algorithm by a factor of O(J(U-L)M2UlogJUlog(U-L)). We explore some interesting observations, which make possible to apply the divide-and-conquer strategy combined with dynamic programming. Our algorithm is also based on computing optimal paths in an implicitly represented graph.