CenteredTransformInitializer with only TranslationTransform?

I am trying to register two 3D CT scans using SimpleITK. After checking they have the same orientation, I load them from .nii.gz files. Then they look like this (central axial slice displayed):
Fixed image:
image
Moving image:
image

To initialize the registration, following this tutorial we first need to align the two volumes. However, after doing this:

initial_transform = sitk.CenteredTransformInitializer(fixed_image, 
                                                    moving_image, 
                                                    sitk.Euler3DTransform(),
                                                    sitk.CenteredTransformInitializerFilter.GEOMETRY
                                                    ) 

moving_resampled = sitk.Resample(moving_image, fixed_image, initial_transform, sitk.sitkLinear, 0.0, moving_image.GetPixelID())

The moving_resampled image is flipped upside down:
image

Is this normal behavior?

As an alternative, I tried to just align the images using a 3D translation, which gives an error:

initial_transform = sitk.CenteredTransformInitializer(fixed_image, 
                                                    moving_image, 
                                                    sitk.TranslationTransform(3),#sitk.Euler3DTransform(),
                                                    sitk.CenteredTransformInitializerFilter.GEOMETRY,
                                                    ) #  .MOMENTS)

moving_resampled = sitk.Resample(moving_image, fixed_image, initial_transform, sitk.sitkLinear, 0.0, moving_image.GetPixelID())

File “C:\Users\stijnb\AppData\Local\Continuum\miniconda3\envs\mimicsenv352\lib\site-packages\SimpleITK\SimpleITK.py”, line 6169, in CenteredTransformInitializer
**return _SimpleITK.CenteredTransformInitializer(*args, kwargs)
RuntimeError: Exception thrown in SimpleITK CenteredTransformInitializer: D:\a\1\sitk\Code\BasicFilters\src\sitkCenteredTransformInitializerFilter.cxx:132:
sitk::ERROR: Error converting input transform to required transform type with center.

Any suggestions how this can be solved? Thanks!

Hello @sdbonte,

Hard to debug without the short code used here. This is possibly a display issue.

When working with 3D images highly recommended to use an external viewer. Fiji is the default in SimpleITK, ITK-SNAP highly recommended for quick image viewing, see this notebook for details.

Short code snippet:

import SimpleITK as sitk

fixed_image_file = 'a.nii.gz'
moving_image_file = 'b.nii.gz'

fixed_image = sitk.ReadImage(fixed_image_file, sitk.sitkFloat32)
moving_image = sitk.ReadImage(moving_image_file, sitk.sitkFloat32)

sitk.Show(fixed_image, 'fixed')
sitk.Show(moving_image, 'moving')

initial_transform = sitk.CenteredTransformInitializer(fixed_image, 
                                                    moving_image, 
                                                    sitk.Euler3DTransform(),
                                                    sitk.CenteredTransformInitializerFilter.GEOMETRY
                                                    )
moving_resampled = sitk.Resample(moving_image, fixed_image, initial_transform, sitk.sitkLinear, 0.0, moving_image.GetPixelID())

sitk.Show(moving_resampled, 'moving_resampled')

Meaning of error message:
The CenteredTransformInitializer is expecting a transformation which has a center, TranslationTransform is not one of the transformations that has a center, hence the error. For additional details about transformations see this notebook.

1 Like

I also met this problem. Have you solved it?