20 import SimpleITK
as sitk
25 def command_iteration(method):
27 f
"{method.GetOptimizerIteration():3} "
28 + f
" = {method.GetMetricValue():7.5f} "
29 + f
" : {method.GetOptimizerPosition()}"
37 "ImageRegistrationMethod2",
38 "<fixedImageFilter> <movingImageFile> <outputTransformFile>",
52 R.SetMetricAsJointHistogramMutualInformation()
54 R.SetOptimizerAsGradientDescentLineSearch(
56 numberOfIterations=200,
57 convergenceMinimumValue=1e-5,
58 convergenceWindowSize=5,
63 R.SetInterpolator(sitk.sitkLinear)
65 R.AddCommand(sitk.sitkIterationEvent,
lambda: command_iteration(R))
67 outTx = R.Execute(fixed, moving)
71 print(f
"Optimizer stop condition: {R.GetOptimizerStopConditionDescription()}")
72 print(f
" Iteration: {R.GetOptimizerIteration()}")
73 print(f
" Metric value: {R.GetMetricValue()}")
78 resampler.SetReferenceImage(fixed)
79 resampler.SetInterpolator(sitk.sitkLinear)
80 resampler.SetDefaultPixelValue(1)
81 resampler.SetTransform(outTx)
83 out = resampler.Execute(moving)
87 cimg =
sitk.Compose(simg1, simg2, simg1 // 2.0 + simg2 // 2.0)
89 return {
"fixed": fixed,
94 if __name__ ==
"__main__":
95 return_dict = main(sys.argv)
96 if "SITK_NOSHOW" not in os.environ:
97 sitk.Show(return_dict[
"composition"],
"ImageRegistration2 Composition")
SITKCommon_EXPORT void WriteTransform(const Transform &transform, const std::string &filename)
Image Normalize(const Image &image1)
Normalize an image by setting its mean to zero and variance to one.
Image RescaleIntensity(const Image &image1, double outputMinimum=0, double outputMaximum=255)
Applies a linear transformation to the intensity levels of the input Image .
void SITKIO_EXPORT Show(const Image &image, const std::string &title="", const bool debugOn=ProcessObject::GetGlobalDefaultDebug())
SITKIO_EXPORT Image ReadImage(const std::vector< std::string > &fileNames, PixelIDValueEnum outputPixelType=sitkUnknown, const std::string &imageIO="")
ReadImage is a procedural interface to the ImageSeriesReader class which is convenient for most image...
Image Cast(const Image &image, PixelIDValueEnum pixelID)
Image DiscreteGaussian(const Image &image1, std::vector< double > variance=std::vector< double >(3, 1.0), unsigned int maximumKernelWidth=32u, std::vector< double > maximumError=std::vector< double >(3, 0.01), bool useImageSpacing=true)
Blurs an image by separable convolution with discrete gaussian kernels. This filter performs Gaussian...
Resample an image via a coordinate transform.
Image Compose(const Image &image1, const Image &image2, const Image &image3, const Image &image4, const Image &image5)
ComposeImageFilter combine several scalar images into a multicomponent image.
An interface method to the modular ITKv4 registration framework.