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)
50 demons.SetNumberOfIterations(200)
51 demons.SetStandardDeviations(1.0)
53 demons.AddCommand( sitk.sitkIterationEvent,
lambda: command_iteration(demons) )
55 if len( sys.argv ) > 4:
57 sys.argv[-1] = sys.argv.pop()
60 toDisplacementFilter.SetReferenceImage(fixed)
62 displacementField = toDisplacementFilter.Execute(initialTransform)
64 displacementField = demons.Execute(fixed, moving, displacementField)
68 displacementField = demons.Execute(fixed, moving)
72 print(
"Number Of Iterations: {0}".format(demons.GetElapsedIterations()))
73 print(
" RMS: {0}".format(demons.GetRMSChange()))
79 if (
not "SITK_NOSHOW" in os.environ):
82 resampler.SetReferenceImage(fixed);
83 resampler.SetInterpolator(sitk.sitkLinear)
84 resampler.SetDefaultPixelValue(100)
85 resampler.SetTransform(outTx)
87 out = resampler.Execute(moving)
91 sitk.Show( cimg,
"DeformableRegistration1 Composition" )