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(),
33 print(
"Usage:", sys.argv[0],
"<fixedImageFilter> <movingImageFile>",
34 "[initialTransformFile] <outputTransformFile>")
42 if (fixed.GetPixelID()
in (sitk.sitkUInt8, sitk.sitkInt8)):
43 matcher.SetNumberOfHistogramLevels(128)
45 matcher.SetNumberOfHistogramLevels(1024)
46 matcher.SetNumberOfMatchPoints(7)
47 matcher.ThresholdAtMeanIntensityOn()
48 moving = matcher.Execute(moving, fixed)
54 demons.SetNumberOfIterations(200)
56 demons.SetStandardDeviations(1.0)
58 demons.AddCommand(sitk.sitkIterationEvent,
lambda: command_iteration(demons))
62 sys.argv[-1] = sys.argv.pop()
65 toDisplacementFilter.SetReferenceImage(fixed)
67 displacementField = toDisplacementFilter.Execute(initialTransform)
69 displacementField = demons.Execute(fixed, moving, displacementField)
73 displacementField = demons.Execute(fixed, moving)
76 print(
"Number Of Iterations: {0}".format(demons.GetElapsedIterations()))
77 print(
" RMS: {0}".format(demons.GetRMSChange()))
83 if (
"SITK_NOSHOW" not 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)
93 cimg =
sitk.Compose(simg1, simg2, simg1 // 2. + simg2 // 2.)
94 sitk.Show(cimg,
"DeformableRegistration1 Composition")