SuperElastix / SimpleElastix

Multi-lingual medical image registration library
http://simpleelastix.github.io
Apache License 2.0
509 stars 149 forks source link

How to apply transformation with multiple calculated parameter files? #420

Closed binarycai closed 3 years ago

binarycai commented 3 years ago

I've registered two images via point based image registration. Trying to transform other images with generated parameter files(“TransformParameters.0.txt TransformParameters.1.txt TransformParameters.2.txt”) but failed.

Codes pasted below: import SimpleITK as sitk

read parameter files

parameter0=sitk.ReadParameterFile("TransformParameters.0.txt") parameter1=sitk.ReadParameterFile("TransformParameters.1.txt") parameter2=sitk.ReadParameterFile("TransformParameters.2.txt")

set parameter maps

myfilter=sitk.ElastixImageFilter() myfilter.SetParameterMap(parameter0) myfilter.AddParameterMap(parameter1) myfilter.AddParameterMap(parameter2)

movingimg=sitk.ReadImage("slicesmarker02.tif") fixedimg=sitk.ReadImage("slicesmarker01.tif") myfilter.SetMovingImage(movingimg) myfilter.SetFixedImage(fixedimg) myfilter.Execute()

What could I do to fix this?

WARNING: The parameter "Registration", requested at entry number 0, does not exist at all. The default value "MultiResolutionRegistration" is used instead. WARNING: The parameter "FixedImagePyramid", requested at entry number 0, does not exist at all. The default value "FixedSmoothingImagePyramid" is used instead. WARNING: The parameter "MovingImagePyramid", requested at entry number 0, does not exist at all. The default value "MovingSmoothingImagePyramid" is used instead. WARNING: The parameter "ImageSampler", requested at entry number 0, does not exist at all. The default value "" is used instead. WARNING: The parameter "Interpolator", requested at entry number 0, does not exist at all. The default value "BSplineInterpolator" is used instead. WARNING: The parameter "Metric", requested at entry number 0, does not exist at all. The default value "" is used instead. ERROR: the following component has not been specified: Metric WARNING: The parameter "Optimizer", requested at entry number 0, does not exist at all. The default value "" is used instead. ERROR: the following component has not been specified: Optimizer ERROR: One or more components could not be created. Traceback (most recent call last): File "D:/MyProjects/Python Projects/pointransform/main.py", line 18, in myfilter.Execute() File "C:\Users\cly\AppData\Local\Programs\Python\Python38\lib\site-packages\simpleitk-2.0.0rc2.dev908+g8244e-py3.8-win-amd64.egg\SimpleITK\SimpleITK.py", line 11130, in Execute return _SimpleITK.ElastixImageFilter_Execute(self) RuntimeError: Exception thrown in SimpleITK ElastixImageFilter_Execute: D:\packes for cmake compiling\SITK\SimpleElastix\Code\Elastix\src\sitkElastixImageFilterImpl.cxx:259: sitk::ERROR: itk::ExceptionObject (00000031DFBEC1F0) Location: "unknown" File: d:\extralibs\sitk\elastix\core\main\elxElastixFilter.hxx Line: 253 Description: itk::ERROR: ElastixFilter(0000018AF89DA770): Internal elastix error: See elastix log (use LogToConsoleOn() or LogToFileOn()).

sorenchr2011 commented 3 years ago

Hi, See how to get the final transformparametermap and how to use transformix to apply it under the section where transformix is mentioned: https://simpleelastix.readthedocs.io/HelloWorld.html

On Thu, Mar 18, 2021 at 2:15 PM binarycai @.***> wrote:

I've registered two images via point based image registration. Trying to transform other images with generated parameter files(“TransformParameters.0.txt TransformParameters.1.txt TransformParameters.2.txt”) but failed.

Codes pasted below: import SimpleITK as sitk

read parameter files

parameter0=sitk.ReadParameterFile("TransformParameters.0.txt") parameter1=sitk.ReadParameterFile("TransformParameters.1.txt") parameter2=sitk.ReadParameterFile("TransformParameters.2.txt")

set parameter maps

myfilter=sitk.ElastixImageFilter() myfilter.SetParameterMap(parameter0) myfilter.AddParameterMap(parameter1) myfilter.AddParameterMap(parameter2)

movingimg=sitk.ReadImage("slicesmarker02.tif") fixedimg=sitk.ReadImage("slicesmarker01.tif") myfilter.SetMovingImage(movingimg) myfilter.SetFixedImage(fixedimg) myfilter.Execute()

What could I do to fix this?

WARNING: The parameter "Registration", requested at entry number 0, does not exist at all. The default value "MultiResolutionRegistration" is used instead. WARNING: The parameter "FixedImagePyramid", requested at entry number 0, does not exist at all. The default value "FixedSmoothingImagePyramid" is used instead. WARNING: The parameter "MovingImagePyramid", requested at entry number 0, does not exist at all. The default value "MovingSmoothingImagePyramid" is used instead. WARNING: The parameter "ImageSampler", requested at entry number 0, does not exist at all. The default value "" is used instead. WARNING: The parameter "Interpolator", requested at entry number 0, does not exist at all. The default value "BSplineInterpolator" is used instead. WARNING: The parameter "Metric", requested at entry number 0, does not exist at all. The default value "" is used instead. ERROR: the following component has not been specified: Metric WARNING: The parameter "Optimizer", requested at entry number 0, does not exist at all. The default value "" is used instead. ERROR: the following component has not been specified: Optimizer ERROR: One or more components could not be created. Traceback (most recent call last): File "D:/MyProjects/Python Projects/pointransform/main.py", line 18, in myfilter.Execute() File "C:\Users\cly\AppData\Local\Programs\Python\Python38\lib\site-packages\simpleitk-2.0.0rc2.dev908+g8244e-py3.8-win-amd64.egg\SimpleITK\SimpleITK.py", line 11130, in Execute return _SimpleITK.ElastixImageFilter_Execute(self) RuntimeError: Exception thrown in SimpleITK ElastixImageFilter_Execute: D:\packes for cmake compiling\SITK\SimpleElastix\Code\Elastix\src\sitkElastixImageFilterImpl.cxx:259: sitk::ERROR: itk::ExceptionObject (00000031DFBEC1F0) Location: "unknown" File: d:\extralibs\sitk\elastix\core\main\elxElastixFilter.hxx Line: 253 Description: itk::ERROR: ElastixFilter(0000018AF89DA770): Internal elastix error: See elastix log (use LogToConsoleOn() or LogToFileOn()).

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/SuperElastix/SimpleElastix/issues/420, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHBDDPXHKALCGYQYYF5E3LTEH4GPANCNFSM4ZMTF7CA .

binarycai commented 3 years ago

Thank you! Problems have been solved.I should have used transformix.

binarycai commented 3 years ago

New codes below:

import SimpleITK as sitk

parameter0=sitk.ReadParameterFile("TransformParameters.0.txt") parameter1=sitk.ReadParameterFile("TransformParameters.1.txt") parameter2=sitk.ReadParameterFile("TransformParameters.2.txt")

myfilter=sitk.TransformixImageFilter()

myfilter.SetTransformParameterMap(parameter0) myfilter.AddTransformParameterMap(parameter1) myfilter.AddTransformParameterMap(parameter2)

movingimg=sitk.ReadImage("slicesmarker02.tif")

myfilter.SetMovingImage(movingimg) myfilter.Execute() sitk.WriteImage(myfilter.GetResultImage(),"result02.nii")