1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19""" An example showing how to use SimpleITK's GeodesicActiveContourLevelSetImageFilter """
20
21import os
22import sys
23
24import SimpleITK as sitk
25
26if len(sys.argv) < 8:
27 print(
28 "Usage:",
29 sys.argv[0],
30 "<inputImage> <outputImage> <sigma> <InitialDistance>",
31 "<PropagationScaling> <seedX> <seedY> <seedZ>",
32 )
33 sys.exit(1)
34
35inputImage = sys.argv[1]
36outputImage = sys.argv[2]
37sigma = float(sys.argv[3])
38initialDistance = float(sys.argv[4])
39propagationScaling = float(sys.argv[5])
40seed = [float(sys.argv[6]), float(sys.argv[7])]
41
42if len(sys.argv) > 8:
43 seed.append(float(sys.argv[8]))
44
46reader.SetFileName(inputImage)
47image = reader.Execute()
48
50gradientMagnitude.SetSigma(sigma)
51
53
54seedImage =
sitk.Image(image.GetSize()[0], image.GetSize()[1], sitk.sitkUInt8)
55seedImage.SetSpacing(image.GetSpacing())
56seedImage.SetOrigin(image.GetOrigin())
57seedImage.SetDirection(image.GetDirection())
58seedImage[seedImage.TransformPhysicalPointToIndex(seed)] = 1
59
61distance.InsideIsPositiveOff()
62distance.UseImageSpacingOn()
63
65initialImage =
sitk.Cast(initialImage, featureImage.GetPixelID()) * -1 + 0.5
66
68geodesicActiveContour.SetPropagationScaling(propagationScaling)
69geodesicActiveContour.SetCurvatureScaling(0.5)
70geodesicActiveContour.SetAdvectionScaling(1.0)
71geodesicActiveContour.SetMaximumRMSError(0.01)
72geodesicActiveContour.SetNumberOfIterations(1000)
73
74levelset = geodesicActiveContour.Execute(initialImage, featureImage)
75
76print("RMS Change: ", geodesicActiveContour.GetRMSChange())
77print("Elapsed Iterations: ", geodesicActiveContour.GetElapsedIterations())
78
80
81if "SITK_NOSHOW" not in os.environ:
Segments structures in images based on a user supplied edge potential map.
Computes the Magnitude of the Gradient of an image by convolution with the first derivative of a Gaus...
Read an image file and return a SimpleITK Image.
The Image class for SimpleITK.
This filter calculates the Euclidean distance transform of a binary image in linear time for arbitrar...
void SITKIO_EXPORT Show(const Image &image, const std::string &title="", const bool debugOn=ProcessObject::GetGlobalDefaultDebug())
Image BoundedReciprocal(Image &&image1)
Computes 1/(1+x) for each pixel in the image.
Image BinaryContour(Image &&image1, bool fullyConnected=false, double backgroundValue=0.0, double foregroundValue=1.0)
Labels the pixels on the border of the objects in a binary image.
Image LabelOverlay(Image &&image, const Image &labelImage, double opacity=0.5, double backgroundValue=0.0, std::vector< uint8_t > colormap=std::vector< uint8_t >())
Apply a colormap to a label image and put it on top of the input image.
Image BinaryThreshold(Image &&image1, double lowerThreshold=0.0, double upperThreshold=255.0, uint8_t insideValue=1u, uint8_t outsideValue=0u)
Binarize an input image by thresholding.
Image Cast(const Image &image, PixelIDValueEnum pixelID)