20 """ A SimpleITK example demonstrating the classic Demons image registration. """
24 import SimpleITK
as sitk
27 def command_iteration(sitk_filter):
28 """ Callback invoked when the filter processes an iteration. """
29 print(f
"{sitk_filter.GetElapsedIterations():3} = {sitk_filter.GetMetric():10.5f}")
34 f
"Usage: {sys.argv[0]}"
35 +
" <fixedImageFilter> <movingImageFile> <outputTransformFile>"
44 matcher.SetNumberOfHistogramLevels(1024)
45 matcher.SetNumberOfMatchPoints(7)
46 matcher.ThresholdAtMeanIntensityOn()
47 moving = matcher.Execute(moving, fixed)
53 demons.SetNumberOfIterations(50)
55 demons.SetStandardDeviations(1.0)
57 demons.AddCommand(sitk.sitkIterationEvent,
lambda: command_iteration(demons))
59 displacementField = demons.Execute(fixed, moving)
62 print(f
"Number Of Iterations: {demons.GetElapsedIterations()}")
63 print(f
" RMS: {demons.GetRMSChange()}")
69 if "SITK_NOSHOW" not in os.environ:
71 resampler.SetReferenceImage(fixed)
72 resampler.SetInterpolator(sitk.sitkLinear)
73 resampler.SetDefaultPixelValue(100)
74 resampler.SetTransform(outTx)
76 out = resampler.Execute(moving)
82 cimg =
sitk.Compose(simg1, simg2, simg1 // 2.0 + simg2 // 2.0)
83 sitk.Show(cimg,
"DeformableRegistration1 Composition")