20 """ A SimpleITK example demonstrating fast symmetric forces Demons image
25 import SimpleITK
as sitk
28 def command_iteration(sitk_filter):
29 """ Callback invoked when the filter progresses. """
30 print(f
"{sitk_filter.GetElapsedIterations():3} = {sitk_filter.GetMetric():10.5f}")
37 "<fixedImageFilter> <movingImageFile>",
38 "[initialTransformFile] <outputTransformFile>",
47 if fixed.GetPixelID()
in (sitk.sitkUInt8, sitk.sitkInt8):
48 matcher.SetNumberOfHistogramLevels(128)
50 matcher.SetNumberOfHistogramLevels(1024)
51 matcher.SetNumberOfMatchPoints(7)
52 matcher.ThresholdAtMeanIntensityOn()
53 moving = matcher.Execute(moving, fixed)
59 demons.SetNumberOfIterations(200)
61 demons.SetStandardDeviations(1.0)
63 demons.AddCommand(sitk.sitkIterationEvent,
lambda: command_iteration(demons))
67 sys.argv[-1] = sys.argv.pop()
70 toDisplacementFilter.SetReferenceImage(fixed)
72 displacementField = toDisplacementFilter.Execute(initialTransform)
74 displacementField = demons.Execute(fixed, moving, displacementField)
78 displacementField = demons.Execute(fixed, moving)
81 print(f
"Number Of Iterations: {demons.GetElapsedIterations()}")
82 print(f
" RMS: {demons.GetRMSChange()}")
88 if "SITK_NOSHOW" not in os.environ:
90 resampler.SetReferenceImage(fixed)
91 resampler.SetInterpolator(sitk.sitkLinear)
92 resampler.SetDefaultPixelValue(100)
93 resampler.SetTransform(outTx)
95 out = resampler.Execute(moving)
98 cimg =
sitk.Compose(simg1, simg2, simg1 // 2.0 + simg2 // 2.0)
99 sitk.Show(cimg,
"DeformableRegistration1 Composition")