23 import SimpleITK
as sitk
29 "<inputImage> <outputImage> <sigma> <InitialDistance>",
30 "<PropagationScaling> <seedX> <seedY> <?seedZ>",
34 inputImage = sys.argv[1]
35 outputImage = sys.argv[2]
36 sigma = float(sys.argv[3])
37 initialDistance = float(sys.argv[4])
38 propagationScaling = float(sys.argv[5])
39 seed = [float(sys.argv[6]), float(sys.argv[7])]
42 seed.append(float(sys.argv[8]))
45 reader.SetFileName(inputImage)
46 image = reader.Execute()
49 gradientMagnitude.SetSigma(sigma)
53 seedImage =
sitk.Image(image.GetSize()[0], image.GetSize()[1], sitk.sitkUInt8)
54 seedImage.SetSpacing(image.GetSpacing())
55 seedImage.SetOrigin(image.GetOrigin())
56 seedImage.SetDirection(image.GetDirection())
57 seedImage[seedImage.TransformPhysicalPointToIndex(seed)] = 1
60 distance.InsideIsPositiveOff()
61 distance.UseImageSpacingOn()
64 initialImage =
sitk.Cast(initialImage, featureImage.GetPixelID()) * -1 + 0.5
67 geodesicActiveContour.SetPropagationScaling(propagationScaling)
68 geodesicActiveContour.SetCurvatureScaling(0.5)
69 geodesicActiveContour.SetAdvectionScaling(1.0)
70 geodesicActiveContour.SetMaximumRMSError(0.01)
71 geodesicActiveContour.SetNumberOfIterations(1000)
73 levelset = geodesicActiveContour.Execute(initialImage, featureImage)
75 print(
"RMS Change: ", geodesicActiveContour.GetRMSChange())
76 print(
"Elapsed Iterations: ", geodesicActiveContour.GetElapsedIterations())
80 if "SITK_NOSHOW" not in os.environ: