20 """ A SimpleITK example demonstrating image registration with histogram
21 mutual information as a similarity measure. """
25 import SimpleITK
as sitk
28 def command_iteration(method):
29 """ Callback invoked when the optimization process is running. """
31 f
"{method.GetOptimizerIteration():3} "
32 + f
" = {method.GetMetricValue():7.5f} "
33 + f
" : {method.GetOptimizerPosition()}"
38 """ A SimpleITK example demonstrating image registration with histogram
39 mutual information as a similarity measure. """
43 "ImageRegistrationMethod2",
44 "<fixedImageFilter> <movingImageFile> <outputTransformFile>",
58 R.SetMetricAsJointHistogramMutualInformation()
60 R.SetOptimizerAsGradientDescentLineSearch(
62 numberOfIterations=200,
63 convergenceMinimumValue=1e-5,
64 convergenceWindowSize=5,
69 R.SetInterpolator(sitk.sitkLinear)
71 R.AddCommand(sitk.sitkIterationEvent,
lambda: command_iteration(R))
73 outTx = R.Execute(fixed, moving)
77 print(f
"Optimizer stop condition: {R.GetOptimizerStopConditionDescription()}")
78 print(f
" Iteration: {R.GetOptimizerIteration()}")
79 print(f
" Metric value: {R.GetMetricValue()}")
84 resampler.SetReferenceImage(fixed)
85 resampler.SetInterpolator(sitk.sitkLinear)
86 resampler.SetDefaultPixelValue(1)
87 resampler.SetTransform(outTx)
89 out = resampler.Execute(moving)
93 cimg =
sitk.Compose(simg1, simg2, simg1 // 2.0 + simg2 // 2.0)
95 return {
"fixed": fixed,
"moving": moving,
"composition": cimg}
98 if __name__ ==
"__main__":
99 return_dict = main(sys.argv)
100 if "SITK_NOSHOW" not in os.environ:
101 sitk.Show(return_dict[
"composition"],
"ImageRegistration2 Composition")
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())
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.
SITKCommon_EXPORT void WriteTransform(const Transform &transform, const PathType &filename)
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.
SITKIO_EXPORT Image ReadImage(const std::vector< PathType > &fileNames, PixelIDValueEnum outputPixelType=sitkUnknown, const std::string &imageIO="")
ReadImage is a procedural interface to the ImageSeriesReader class which is convenient for most image...