19 from __future__
import print_function
21 import SimpleITK
as sitk
25 if len ( sys.argv ) < 8:
26 print(
"Usage:", sys.argv[0],
" <inputImage> <outputImage> <sigma> <InitialDistance> <PropagationScaling> <seedX> <seedY> <?seedZ>" )
29 inputImage = sys.argv[1]
30 outputImage = sys.argv[2]
31 sigma = float(sys.argv[3])
32 initialDistance = float(sys.argv[4])
33 propagationScaling = float(sys.argv[5])
34 seed = [float(sys.argv[6]), float(sys.argv[7]) ]
36 if len( sys.argv ) > 8:
37 seed.append( float(sys.argv[8]) )
41 reader.SetFileName ( inputImage )
42 image = reader.Execute()
45 gradientMagnitude.SetSigma( sigma )
49 seedImage =
sitk.Image( image.GetSize()[0], image.GetSize()[1], sitk.sitkUInt8 )
50 seedImage.SetSpacing( image.GetSpacing() )
51 seedImage.SetOrigin( image.GetOrigin() )
52 seedImage.SetDirection( image.GetDirection() )
53 seedImage[ seedImage.TransformPhysicalPointToIndex(seed) ] = 1
56 distance.InsideIsPositiveOff()
57 distance.UseImageSpacingOn()
60 initialImage =
sitk.Cast( initialImage, featureImage.GetPixelID() ) * -1 + 0.5
64 geodesicActiveContour.SetPropagationScaling( propagationScaling )
65 geodesicActiveContour.SetCurvatureScaling( .5 )
66 geodesicActiveContour.SetAdvectionScaling( 1.0 )
67 geodesicActiveContour.SetMaximumRMSError( 0.01 )
68 geodesicActiveContour.SetNumberOfIterations( 1000 )
70 levelset = geodesicActiveContour.Execute( initialImage, featureImage )
72 print(
"RMS Change: ", geodesicActiveContour.GetRMSChange() )
73 print(
"Elapsed Iterations: ", geodesicActiveContour.GetElapsedIterations() )
77 if (
not "SITK_NOSHOW" in os.environ ):