CT-MRI registration: Error when initialising images centre

Hello,

I’m at the beginning of registering CT and MRI dicom files of the thorax, and I’m stuck on the part of finding the centre of the images. I get the following error message:

RuntimeError: Exception thrown in SimpleITK CenteredTransformInitializer: /Users/runner/work/1/sitk/Code/BasicFilters/src/sitkCenteredTransformInitializerFilter.cxx:85:
sitk::ERROR: Moving Image parameter for CenteredTransformInitializerFilter doesn’t match type or dimension!

this is the bit (same as tutorial 05):
initial_transform = sitk.CenteredTransformInitializer(
fixed_image,
moving_image,
sitk.Euler3DTransform(),
sitk.CenteredTransformInitializerFilter.GEOMETRY,
)

gui.RegistrationPointDataAquisition(
fixed_image,
moving_image,
figure_size=(8, 4),
known_transformation=initial_transform,
fixed_window_level=ct_window_level,
moving_window_level=mr_window_level,
);

I’ve been looking at the images metadata, but I can’t find any problem there. Please, do you have any suggestion? Thanks

Hello @Priscilla,

The error message is telling us that something isn’t as expected with the moving_image. From the code we see that we are expecting 3D images, usage of Euler3DTransform.
First step in helping us help you debug, share the metadata with us (we don’t know what you saw when you looked at the metadata):

# see both the size and dimensionality of the image in one print
print(moving_image.GetSize())
print(moving_image.GetPixelIDTypeAsString()
#also look at the fixed image
print(fixed_image.GetSize())
print(fixed_image.GetPixelIDTypeAsString()
1 Like

Hi Ziv,

Thank you very much for your reply. I’ve attached the metadata corresponding to the first scan from each CT and 13C-MRI stack of scans. These data are raw and not preprocessed. I’m also looking at 1H-MRI (axial) and modified CT_mod (from coronal to axial). All data sets present the same error I mentioned in my previous message – but not with the same modality, like CT-CT_mod, 13CMR-1H-MR, etc. (I tested this, just in case).

If you need more information:
I want to perform multimodal (CT/MRI) deformable registration for a kidney tumour. I’ve got scans of the whole thorax, unfortunately not useful to get landmarks because the kidneys have different relative positions with respect to possible landmarks, e.g. spine or internal organs.

If you could point me to any other relevant tutorials or documentation on this, I’ll be very grateful.

Best wishes,

Priscilla

CMR.txt (21.3 KB)

ct_raw.txt (2.84 KB)

Hello @Priscilla,

Please just report the results of reading the images and then running the print commands as given in the previous post. The problem is not with the images on disk, which is what the metadata reflects, it is with the image in memory, pixel type and size/dimensionality. These need to match the types expected by the CenteredTransformInitializer.

Hello Ziv,

Apologies, somehow I missed your previous message. Here is the output you requested:

(256, 256, 72)
16-bit signed integer
(256, 256, 72) 

16-bit unsigned integer

here moving image is H1-MRI (sampled) and fixed image is rotated CT (from axial to coronal)

Many thanks for your help.

Regards,

Priscilla

Hello @Priscilla,

The problem is due to the different pixel types (underlying templated C++ details which won’t go into). As you are working on registration, the images are expected to have a pixel type of float (sitk.sitkFloat32 or sitk.sitkFloat64). This can be enforced in the read operation or after the fact via explicit casting. See code below illustrating the problem and solutions:

import SimpleITK as sitk

# Read the fixed and moving images from disk. Get the file names for each with
# GDCMSeries..., assuming they are DICOM series.
# In the read operation we are also casting both to float, which is required by
# registration framework:
#fixed_image = sitk.ReadImage(fixed_image_file_names, sitk.sitkFloat32)
#moving_image = sitk.ReadImage(moving_image_file_names, sitk.sitkFloat32)

fixed_image = sitk.Image((256, 256, 72), sitk.sitkInt16)
moving_image = sitk.Image((256, 256, 72), sitk.sitkUInt16)

# Uncomment the following line, casting both images to float solves the issue
#fixed_image = sitk.Cast(fixed_image, sitk.sitkFloat32)
#moving_image = sitk.Cast(moving_image, sitk.sitkFloat32)

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

Thank you very much Zivy!