Bspline Free form deformable registration

Hello .
I’m trying to register two lung CT images from the same patient (baseline and post ) using the Bspline transformation algorithm . I have the dicom images as well as the lung and the airway masks . I have already segmented these scans . So my question is
Should I be using the dicom images or mask files or saving the dicom images into nrrd file and then using both the nrrd file along with the mask files .

Thank you for your help.

While using airways would provide a great deal of information to work with, I am unaware of a ready way to use them.

You could use lung masks to do rigid or affine registration, and use that to initialize BSpline which would operate on CT intensities. Take a look at DeformableRegistration15 example.

Thank you so much . This is the pipeline that I would be using eventually . Can I incorporate this example in python . Is there an example that you could guide me to for python .

Thank you once again

For Python registration code, take a look at Perform2DTranslationRegistrationWithMeanSquares. It has associated C++ code, so it should be helpful in translating DeformableRegistration15.cxx into Python.

Thank you so much for your help. Really appreciated .

So is there a way I could use the affine registration example along with the bspline non rigid example as shown in simpleITK-notebooks/python for my registration process.
So far I performed affine registration on the lung masks . This is what I have for that iteration
fixed nd moving
iter

You could save to file the transform you obtain from that step, and then load it for BSpline transform. This allows you to remove the code from the example which does the rigid transform.

Okay perfect . Thank you . I will try that .
I am trying to wrap my head around the output of my affine transformation. So the below figure for the affine transformation is blank . Can you provide some insights of why this might be happening .

Thank you so much again . fig

Note that you are using a mask that prevents the registration algorithm to use the very strong and clear outer boundary of the lungs. This may make the registration less accurate and less robust. I would recommend to dilate the lung mask by 5-10mm to include a bit of the surrounding tissues and use that for registration.

If you register images of the same patient, same breathing phase, and time between acquiring the images is not too long (weeks or months) then you may get even better results by tight cropping with a 3D box and not using masking at all.

If your masks have a value of 1, then you might need to adjust your visualization parameters. Or change your masks to use the value of 255, which visualize without issues.

Okay thank you so much . I will try that . :slight_smile:

I used this function for setting the upper bounds for my fixed and moving images to 255 .
#set all values that are 1 to 255
sitk.Clamp(Moving_image_sitk,upperBound=255)
sitk.Clamp(Fixed_image_sitk,upperBound=255)

I’m still getting the black screen for visualization . This is the final result for my affine transformation which seems to work .

Thank you

What does interact do? Can you write moving_resampled to disk and visualize it using Slicer? How does the file look like?

That is actually a good idea. Thanks .

Looks like saving the moving_resampled onto the drive and opening in slicer made it work .

Thank you .

I have another question regarding initializing the affine transformation center points . I want to initialize the center point of affine transformation at carina point in the fixed image . And the initial transform as difference between the carina points in moving and fixed image .

I have imparted the carina points as a list of vectors [ x, y , z] for both fixed and moving image .
And right now the code only uses this as initial transform
initial_transform = sitk.CenteredTransformInitializer(Fixed_image_sitk,
Moving_image_sitk,
sitk.AffineTransform(3),
sitk.CenteredTransformInitializerFilter.MOMENTS)
And
final_transform = sitk.AffineTransform(initial_transform) as final transform .

Is there a way I could use something like
Fixed_img_carina_points = [ x,y,z]

final_transform = sitk.AffineTransform(initial_transform.GetMatrix,initial_transform.GetTranslation,Fixed_img_carina_points) to compute the final transform .

I hope it makes sense .

Thank you once again
Its just I’m new to registration and SimpleItk toolkit is really helping me

There is LandmarkBasedTransformInitializer, but it needs 4 points or more.

You could keep the current transform initializer, but then do this trick:

and then use this adjusted transform to initialize the affine.

Thank you so much . I will try this approach .

Now I have a final affine transformation saved as a .tfm file . I want to initialize this for my B spline FFD transformation . The code that I’m using is

I have my fixed and moving images as well as fixed image mask = lung airway mask file .

So my question is how do I initialize my already obtained Affine transformation for Bspline .
I’m reading my affine transformation under the variable
affine_transformation = sitk.ReadTransform(os.path.join(output_dir_affine, “AffineTransforamtion_20_21.tfm”))

Thank you :slight_smile:

Make a composite transform of that affine transform and the BSpline you want to work with, see the code here:

then pass compositeTransform to the registration instead of BSpline.

Thank you . I will do that :slight_smile:

So I’m trying to do a Bspline registration where my moving and fixed images are .mha format and my fixed mask is .img ( mask for airway tree )

I’m getting an error

File “C:\Users\singhgau\Anaconda3\lib\site-packages\SimpleITK\SimpleITK.py”, line 10387, in Execute
return _SimpleITK.ImageRegistrationMethod_Execute(self, fixed, moving)

RuntimeError: Exception thrown in SimpleITK ImageRegistrationMethod_Execute: D:\a\1\sitk\Code\Registration\src\sitkImageRegistrationMethod.cxx:791:
sitk::ERROR: Filter does not support fixed image type: 32-bit signed integer

Do I need to cast the image to something else or am I not using the moving and fixed images correctly .

Thank you