SuperElastix / elastix

Official elastix repository
http://elastix.dev
Apache License 2.0
482 stars 116 forks source link

Initial Transform Parameters not being applied #1216

Open han050 opened 2 months ago

han050 commented 2 months ago

Hi, I'm encountering a problem when trying to use the transform parameters from a previous registration as an initial guess for a new registration. It seems that the transform parameters from the previous registration are not being applied, instead, default values are used.

See elastix log:

ELASTIX version: 5.1.0 Command line options from ElastixBase: -out Test_outcome/ -threads unspecified, so all available threads are used Command line options from TransformBase: -t0 Test_outcome/Initial_transform/TransformParameters.0.txt

Reading images... Reading images took 0 ms.

Reading the elastix parameters from file ...

WARNING: The parameter "AutomaticTransformInitializationMethod", requested at entry number 0, does not exist at all. The default value "GeometricalCenter" is used instead. Transform parameters are initialized as: [0, 0, 0, 0, 0, 0]

The transform parameter file looks like this (in short): (Transform "EulerTransform") (TransformParameters 0.0020716847617562382 -0.006290548063643442 0.00033287221727853507 -0.18079999989469725 -0.26997081820522 1.0967064662242103) (InitialTransformParameterFileName "NoInitialTransform") (CenterOfRotationPoint 124.78430071473122 -0.14370068907737732 838.5) (ComputeZYX "false") (Direction 1 0 0 0 1 0 0 0 1) (FixedImageDimension 3) (FixedInternalImagePixelType "float") (HowToCombineTransforms "Compose") (Index 0 0 0)

Could you please help me understand why the transform parameters might not be getting applied, and how I can resolve this issue?

Thank you!

N-Dekker commented 2 months ago

@han050 Thank you for reporting this issue! Can you please try to see if the problem is still there with the latest release, version 5.2.0?

You may download the executable from https://github.com/SuperElastix/elastix/releases/tag/5.2.0

han050 commented 2 months ago

Thanks a lot for the suggestion. Unfortunately, the problem still occurs, but it seems that the initial transform is indeed being used, however it is printed as 'Transform parameters are initialized as: [0, 0, 0, 0, 0, 0]' (see elastix log below). I think that something else might be going wrong in the initial transformation and registration process. Just for my understanding; the initial transform (in my case the result transform parameters from the previous registration) is applied as the first step of the registration on the moving image, and the resulting transform parameters are relative to the initial transform parameters—not the sum of the initial transform and the subsequent registration step. Is this correct?

Besides, the 'result' image is the moving image, with the initial transform parameters + the outcome transform parameters, (if correct performed) on the position of the fixed image, is that correct?

The reason I got confused is because of these sentences in the elastix manual: 2.1 registration framework: "One image, the moving image IM (x), is deformed to fit the other image, the fixed image IF (x)." "The transformation is defined as a mapping from the fixed image to the moving image".

The way I interpret the second sentence is that the transform parameters map the fixed image to the position of the moving image. However, the 'result' image seems to be the opposite—transforming the moving image to align with the fixed image. Can someone clarify these points for me?

Thanks in advance for your help!

ELASTIX version: 5.2.0 Command line options from ElastixBase: -f /Data/fixed.nii.gz -m /Data/moving.nii.gz -fMask /Data/fixed_mask.nii.gz -mMask unspecified, so no moving mask used -out Test_outcome/ -p Parameters/Par0001rigid.txt -threads unspecified, so all available threads are used Command line options from TransformBase: -t0 Test_outcome/Initial_transform/TransformParameters.0.txt

=============== start of ParameterFile: Parameters/Par0001rigid.txt =============== (AutomaticTransformInitialization "false")

(FixedInternalImagePixelType "float") (FixedImageDimension 3) (MovingInternalImagePixelType "float") (MovingImageDimension 3)

(AutomaticParameterEstimation "true") (AutomaticScalesEstimation "true") (CheckNumberOfSamples "true") (DefaultPixelValue 0) (FinalBSplineInterpolationOrder 3) (FixedImagePyramid "FixedSmoothingImagePyramid")

(ImageSampler "RandomCoordinate") (NumberOfSpatialSamples 1000) (NewSamplesEveryIteration "true") (UseRandomSampleRegion "false") (Interpolator "BSplineInterpolator") (Metric "AdvancedNormalizedCorrelation") (ResampleInterpolator "FinalBSplineInterpolator") (Resampler "DefaultResampler") (Transform "EulerTransform") (MovingImagePyramid "MovingSmoothingImagePyramid") (NumberOfResolutions 4) (Optimizer "AdaptiveStochasticGradientDescent") (Registration "MultiResolutionRegistration") (ResultImageFormat "nii") (WriteIterationInfo "false") (WriteResultImage "true") (ShowExactMetricValue "false") (ErodeMask "false") (UseDirectionCosines "true")

=============== end of ParameterFile: Parameters/Par0001rigid.txt ===============

Reading images... Reading images took 2730 ms.

Reading the elastix parameters from file ...

WARNING: the fixed pyramid schedule is not fully specified! A default pyramid schedule is used. WARNING: the moving pyramid schedule is not fully specified! A default pyramid schedule is used. WARNING: The parameter "AutomaticTransformInitializationMethod", requested at entry number 0, does not exist at all. The default value "GeometricalCenter" is used instead. Transform parameters are initialized as: [0, 0, 0, 0, 0, 0] Scales are estimated automatically. Scales for transform parameters are: [22043.046647943454, 5944.416659892168, 26803.78244894689, 1, 1, 1] Initialization of all components (before registration) took: 13 ms. Preparation of the image pyramids took: 1517 ms.

drchrisch commented 2 months ago

Hello @N-Dekker, @han050,

interesting to read. I think I have the same behaviour with ITKElastix (itk-elastix version 0.20.0), but I haven't created a well documented report.

N-Dekker commented 2 months ago

Thanks for the extra information @han050

Just for my understanding; the initial transform (in my case the result transform parameters from the previous registration) is applied as the first step of the registration on the moving image, and the resulting transform parameters are relative to the initial transform parameters—not the sum of the initial transform and the subsequent registration step. Is this correct?

Yes, that is correct 👍

I'll let you know when I have a better understanding of what's going on!

mstaring commented 2 months ago

Is the sentence Transform parameters are initialized as: [0, 0, 0, 0, 0, 0] not simply a statement about the initialization of the current transform, rather than a statement about the initial transform?