Topology Simplification Algorithm for the Segmentation of Medical Scans