20 from __future__
import print_function
21 from functools
import reduce
24 import SimpleITK
as sitk
29 def command_iteration(method) :
30 print(
"{0:3} = {1:7.5f} : {2}".format(method.GetOptimizerIteration(),
31 method.GetMetricValue(),
32 method.GetOptimizerPosition()))
36 if len ( sys.argv ) < 4:
37 print(
"Usage: {0} <fixedImageFilter> <movingImageFile> <outputTransformFile>".format(sys.argv[0]))
40 pixelType = sitk.sitkFloat32
54 R.SetMetricAsJointHistogramMutualInformation()
56 R.SetOptimizerAsGradientDescentLineSearch(learningRate=1.0,
57 numberOfIterations=200,
58 convergenceMinimumValue=1e-5,
59 convergenceWindowSize=5)
63 R.SetInterpolator(sitk.sitkLinear)
65 R.AddCommand( sitk.sitkIterationEvent,
lambda: command_iteration(R) )
67 outTx = R.Execute(fixed, moving)
71 print(
"Optimizer stop condition: {0}".format(R.GetOptimizerStopConditionDescription()))
72 print(
" Iteration: {0}".format(R.GetOptimizerIteration()))
73 print(
" Metric value: {0}".format(R.GetMetricValue()))
78 if (
not "SITK_NOSHOW" in os.environ ):
81 resampler.SetReferenceImage(fixed);
82 resampler.SetInterpolator(sitk.sitkLinear)
83 resampler.SetDefaultPixelValue(1)
84 resampler.SetTransform(outTx)
86 out = resampler.Execute(moving)
91 sitk.Show( cimg,
"ImageRegistration2 Composition" )