24 if len(sys.argv) != 11:
26 "Usage: " + sys.argv[0] +
"<InputFileName> <OutputFileName>"
27 " <seedX> <seedY> <InitialDistance> <Sigma> <SigmoidAlpha> "
28 "<SigmoidBeta> <PropagationScaling> <NumberOfIterations>")
31 inputFileName = sys.argv[1]
32 outputFileName = sys.argv[2]
33 seedPosX = int(sys.argv[3])
34 seedPosY = int(sys.argv[4])
36 initialDistance = float(sys.argv[5])
37 sigma = float(sys.argv[6])
38 alpha = float(sys.argv[7])
39 beta = float(sys.argv[8])
40 propagationScaling = float(sys.argv[9])
41 numberOfIterations = int(sys.argv[10])
42 seedValue = -initialDistance
46 InputPixelType = itk.F
47 OutputPixelType = itk.UC
49 InputImageType =
itk.Image[InputPixelType, Dimension]
50 OutputImageType =
itk.Image[OutputPixelType, Dimension]
55 reader = ReaderType.New()
56 reader.SetFileName(inputFileName)
59 InputImageType, InputImageType]
60 smoothing = SmoothingFilterType.New()
61 smoothing.SetTimeStep(0.125)
62 smoothing.SetNumberOfIterations(5)
63 smoothing.SetConductanceParameter(9.0)
64 smoothing.SetInput(reader.GetOutput())
67 InputImageType, InputImageType]
68 gradientMagnitude = GradientFilterType.New()
69 gradientMagnitude.SetSigma(sigma)
70 gradientMagnitude.SetInput(smoothing.GetOutput())
73 sigmoid = SigmoidFilterType.New()
74 sigmoid.SetOutputMinimum(0.0)
75 sigmoid.SetOutputMaximum(1.0)
76 sigmoid.SetAlpha(alpha)
78 sigmoid.SetInput(gradientMagnitude.GetOutput())
81 InputImageType, InputImageType]
82 fastMarching = FastMarchingFilterType.New()
85 InputImageType, InputImageType, InputPixelType]
86 geodesicActiveContour = GeoActiveContourFilterType.New()
87 geodesicActiveContour.SetPropagationScaling(propagationScaling)
88 geodesicActiveContour.SetCurvatureScaling(1.0)
89 geodesicActiveContour.SetAdvectionScaling(1.0)
90 geodesicActiveContour.SetMaximumRMSError(0.02)
91 geodesicActiveContour.SetNumberOfIterations(numberOfIterations)
92 geodesicActiveContour.SetInput(fastMarching.GetOutput())
93 geodesicActiveContour.SetFeatureImage(sigmoid.GetOutput())
96 InputImageType, OutputImageType]
97 thresholder = ThresholdingFilterType.New()
98 thresholder.SetLowerThreshold(-1000.0)
99 thresholder.SetUpperThreshold(0.0)
102 thresholder.SetInput(geodesicActiveContour.GetOutput())
105 seedPosition[0] = seedPosX
106 seedPosition[1] = seedPosY
109 node.SetValue(seedValue)
110 node.SetIndex(seedPosition)
115 seeds.InsertElement(0, node)
117 fastMarching.SetTrialPoints(seeds)
118 fastMarching.SetSpeedConstant(1.0)
121 InputImageType, OutputImageType]
123 caster1 = CastFilterType.New()
124 caster2 = CastFilterType.New()
125 caster3 = CastFilterType.New()
126 caster4 = CastFilterType.New()
128 writer1 = WriterType.New()
129 writer2 = WriterType.New()
130 writer3 = WriterType.New()
131 writer4 = WriterType.New()
133 caster1.SetInput(smoothing.GetOutput())
134 writer1.SetInput(caster1.GetOutput())
135 writer1.SetFileName(
"GeodesicActiveContourImageFilterOutput1.png")
140 caster2.SetInput(gradientMagnitude.GetOutput())
141 writer2.SetInput(caster2.GetOutput())
142 writer2.SetFileName(
"GeodesicActiveContourImageFilterOutput2.png")
147 caster3.SetInput(sigmoid.GetOutput())
148 writer3.SetInput(caster3.GetOutput())
149 writer3.SetFileName(
"GeodesicActiveContourImageFilterOutput3.png")
154 caster4.SetInput(fastMarching.GetOutput())
155 writer4.SetInput(caster4.GetOutput())
156 writer4.SetFileName(
"GeodesicActiveContourImageFilterOutput4.png")
160 fastMarching.SetOutputSize(
161 reader.GetOutput().GetBufferedRegion().GetSize())
163 writer = WriterType.New()
164 writer.SetFileName(outputFileName)
165 writer.SetInput(thresholder.GetOutput())
169 "Max. no. iterations: " +
170 str(geodesicActiveContour.GetNumberOfIterations()) +
"\n")
173 str(geodesicActiveContour.GetMaximumRMSError()) +
"\n")
175 "No. elpased iterations: " +
176 str(geodesicActiveContour.GetElapsedIterations()) +
"\n")
177 print(
"RMS change: " + str(geodesicActiveContour.GetRMSChange()) +
"\n")
183 mapWriter = InternalWriterType.New()
184 mapWriter.SetInput(fastMarching.GetOutput())
185 mapWriter.SetFileName(
"GeodesicActiveContourImageFilterOutput4.mha")
188 speedWriter = InternalWriterType.New()
189 speedWriter.SetInput(sigmoid.GetOutput())
190 speedWriter.SetFileName(
"GeodesicActiveContourImageFilterOutput3.mha")
193 gradientWriter = InternalWriterType.New()
194 gradientWriter.SetInput(gradientMagnitude.GetOutput())
195 gradientWriter.SetFileName(
"GeodesicActiveContourImageFilterOutput2.mha")
196 gradientWriter.Update()