1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20""" A SimpleITK example demonstrating the FastMarchingImageFilter class. """
21
22import sys
23import SimpleITK as sitk
24
25
26def main(args):
27 """ A SimpleITK example demonstrating the FastMarchingImageFilter class. """
28 if len(args) < 10:
29 print(
30 "Usage:",
31 "FastMarchingSegmentation",
32 "<inputImage> <outputImage> <seedX> <seedY> <Sigma>",
33 "<SigmoidAlpha> <SigmoidBeta> <TimeThreshold>",
34 "<StoppingTime>",
35 )
36 sys.exit(1)
37
38 inputFilename = args[1]
39 outputFilename = args[2]
40
41 seedPosition = (int(args[3]), int(args[4]))
42
43 sigma = float(args[5])
44 alpha = float(args[6])
45 beta = float(args[7])
46 timeThreshold = float(args[8])
47 stoppingTime = float(args[9])
48
50
52 smoothing.SetTimeStep(0.125)
53 smoothing.SetNumberOfIterations(5)
54 smoothing.SetConductanceParameter(9.0)
55 smoothingOutput = smoothing.Execute(inputImage)
56
58 gradientMagnitude.SetSigma(sigma)
59 gradientMagnitudeOutput = gradientMagnitude.Execute(smoothingOutput)
60
62 sigmoid.SetOutputMinimum(0.0)
63 sigmoid.SetOutputMaximum(1.0)
64 sigmoid.SetAlpha(alpha)
65 sigmoid.SetBeta(beta)
66 sigmoidOutput = sigmoid.Execute(gradientMagnitudeOutput)
67
69
70 seedValue = 0
71 trialPoint = (seedPosition[0], seedPosition[1], seedValue)
72
73 fastMarching.AddTrialPoint(trialPoint)
74
75 fastMarching.SetStoppingValue(stoppingTime)
76
77 fastMarchingOutput = fastMarching.Execute(sigmoidOutput)
78
80 thresholder.SetLowerThreshold(0.0)
81 thresholder.SetUpperThreshold(timeThreshold)
82 thresholder.SetOutsideValue(0)
83 thresholder.SetInsideValue(255)
84
85 result = thresholder.Execute(fastMarchingOutput)
86
88
89 image_dict = {
90 "InputImage": inputImage,
91 "SpeedImage": sigmoidOutput,
92 "TimeCrossingMap": fastMarchingOutput,
93 "Segmentation": result,
94 }
95 return image_dict
96
97
98if __name__ == "__main__":
99 return_dict = main(sys.argv)
Binarize an input image by thresholding.
This filter performs anisotropic diffusion on a scalar itk::Image using the modified curvature diffus...
Solve an Eikonal equation using Fast Marching.
Computes the Magnitude of the Gradient of an image by convolution with the first derivative of a Gaus...
Computes the sigmoid function pixel-wise.
SITKIO_EXPORT Image ReadImage(const PathType &filename, PixelIDValueEnum outputPixelType=sitkUnknown, const std::string &imageIO="")
ReadImage is a procedural interface to the ImageFileReader class which is convenient for most image r...
SITKIO_EXPORT void WriteImage(const Image &image, const PathType &fileName, bool useCompression=false, int compressionLevel=-1)
WriteImage is a procedural interface to the ImageFileWriter. class which is convenient for many image...