A shortest path algorithm for optimal boundary extraction in image processing