20 from __future__
import print_function
22 import SimpleITK
as sitk
27 def command_iteration(filter) :
28 print(
"{0:3} = {1:10.5f}".format(filter.GetElapsedIterations(),
31 if len ( sys.argv ) < 4:
32 print(
"Usage: {0} <fixedImageFilter> <movingImageFile> [initialTransformFile] <outputTransformFile>".format(sys.argv[0]))
41 if ( fixed.GetPixelID()
in ( sitk.sitkUInt8, sitk.sitkInt8 ) ):
42 matcher.SetNumberOfHistogramLevels(128)
44 matcher.SetNumberOfHistogramLevels(1024)
45 matcher.SetNumberOfMatchPoints(7)
46 matcher.ThresholdAtMeanIntensityOn()
47 moving = matcher.Execute(moving,fixed)
52 demons.SetNumberOfIterations(200)
54 demons.SetStandardDeviations(1.0)
56 demons.AddCommand( sitk.sitkIterationEvent,
lambda: command_iteration(demons) )
58 if len( sys.argv ) > 4:
60 sys.argv[-1] = sys.argv.pop()
63 toDisplacementFilter.SetReferenceImage(fixed)
65 displacementField = toDisplacementFilter.Execute(initialTransform)
67 displacementField = demons.Execute(fixed, moving, displacementField)
71 displacementField = demons.Execute(fixed, moving)
75 print(
"Number Of Iterations: {0}".format(demons.GetElapsedIterations()))
76 print(
" RMS: {0}".format(demons.GetRMSChange()))
82 if (
not "SITK_NOSHOW" in os.environ):
85 resampler.SetReferenceImage(fixed);
86 resampler.SetInterpolator(sitk.sitkLinear)
87 resampler.SetDefaultPixelValue(100)
88 resampler.SetTransform(outTx)
90 out = resampler.Execute(moving)
94 sitk.Show( cimg,
"DeformableRegistration1 Composition" )