The document describes a method for tracking objects of deformable shapes in images. It proposes representing the matching of a deformable template to an image as a minimum cost cyclic path in a product space of the template and image. An energy functional is introduced that consists of a data term favoring strong image gradients, a shape consistency term favoring similar tangent angles, and an elastic penalty. Optimization is performed using a minimum ratio cycle algorithm parallelized on GPUs. This provides efficient, pixel-accurate segmentation and correspondence between template and image curve. The method can be extended to 4D to segment and track multiple deformable anatomical structures in medical images.