19 from __future__
import print_function
24 import SimpleITK
as sitk
27 print(
"Usage:", sys.argv[0],
28 "<inputImage> <outputImage> <sigma> <InitialDistance>",
29 "<PropagationScaling> <seedX> <seedY> <?seedZ>")
32 inputImage = sys.argv[1]
33 outputImage = sys.argv[2]
34 sigma = float(sys.argv[3])
35 initialDistance = float(sys.argv[4])
36 propagationScaling = float(sys.argv[5])
37 seed = [float(sys.argv[6]), float(sys.argv[7])]
40 seed.append(float(sys.argv[8]))
43 reader.SetFileName(inputImage)
44 image = reader.Execute()
47 gradientMagnitude.SetSigma(sigma)
51 seedImage =
sitk.Image(image.GetSize()[0], image.GetSize()[1], sitk.sitkUInt8)
52 seedImage.SetSpacing(image.GetSpacing())
53 seedImage.SetOrigin(image.GetOrigin())
54 seedImage.SetDirection(image.GetDirection())
55 seedImage[seedImage.TransformPhysicalPointToIndex(seed)] = 1
58 distance.InsideIsPositiveOff()
59 distance.UseImageSpacingOn()
62 initialImage =
sitk.Cast(initialImage, featureImage.GetPixelID()) * -1 + 0.5
65 geodesicActiveContour.SetPropagationScaling(propagationScaling)
66 geodesicActiveContour.SetCurvatureScaling(.5)
67 geodesicActiveContour.SetAdvectionScaling(1.0)
68 geodesicActiveContour.SetMaximumRMSError(0.01)
69 geodesicActiveContour.SetNumberOfIterations(1000)
71 levelset = geodesicActiveContour.Execute(initialImage, featureImage)
73 print(
"RMS Change: ", geodesicActiveContour.GetRMSChange())
74 print(
"Elapsed Iterations: ", geodesicActiveContour.GetElapsedIterations())
78 if (
"SITK_NOSHOW" not in os.environ):