19 """ An example showing how to use SimpleITK's GeodesicActiveContourLevelSetImageFilter """
24 import SimpleITK
as sitk
30 "<inputImage> <outputImage> <sigma> <InitialDistance>",
31 "<PropagationScaling> <seedX> <seedY> <seedZ>",
35 inputImage = sys.argv[1]
36 outputImage = sys.argv[2]
37 sigma = float(sys.argv[3])
38 initialDistance = float(sys.argv[4])
39 propagationScaling = float(sys.argv[5])
40 seed = [float(sys.argv[6]), float(sys.argv[7])]
43 seed.append(float(sys.argv[8]))
46 reader.SetFileName(inputImage)
47 image = reader.Execute()
50 gradientMagnitude.SetSigma(sigma)
54 seedImage =
sitk.Image(image.GetSize()[0], image.GetSize()[1], sitk.sitkUInt8)
55 seedImage.SetSpacing(image.GetSpacing())
56 seedImage.SetOrigin(image.GetOrigin())
57 seedImage.SetDirection(image.GetDirection())
58 seedImage[seedImage.TransformPhysicalPointToIndex(seed)] = 1
61 distance.InsideIsPositiveOff()
62 distance.UseImageSpacingOn()
65 initialImage =
sitk.Cast(initialImage, featureImage.GetPixelID()) * -1 + 0.5
68 geodesicActiveContour.SetPropagationScaling(propagationScaling)
69 geodesicActiveContour.SetCurvatureScaling(0.5)
70 geodesicActiveContour.SetAdvectionScaling(1.0)
71 geodesicActiveContour.SetMaximumRMSError(0.01)
72 geodesicActiveContour.SetNumberOfIterations(1000)
74 levelset = geodesicActiveContour.Execute(initialImage, featureImage)
76 print(
"RMS Change: ", geodesicActiveContour.GetRMSChange())
77 print(
"Elapsed Iterations: ", geodesicActiveContour.GetElapsedIterations())
81 if "SITK_NOSHOW" not in os.environ: