Using the Shape Gradient for Active Contour Segmentation: from the Continuous to the Discrete Formulation