3D Registration of Anatomical and functional MRI of Brain Images

Thank you @zivy . I did that.
ROI_image_distance_map looks good.

However ROI_image_distance_map_resampled is an all black image. I tried with linear as well as Nearest Neighbor resampling. Output is same.

Hello @debapriya,

So you’ve identified that the problem occurs during the resampling step. You will need to debug that, check that all the inputs are indeed as they should be.

I just found that the meta-data of the moving image and ROI_image are different. Assuming this is the cause of the error, I am trying to manually set the meta-data of the ROI_image. However, this is not working. My code is given below:

moving_image = sitk.ReadImage("Coreg/Data1/Moving/mpragegad_reg_reg.nii",sitk.sitkFloat32)

origin = moving_image.GetOrigin()
space = moving_image.GetSpacing()
direction = moving_image.GetDirection()

ROI_image = sitk.ReadImage("Coreg/Data1/intense100.nii", sitk.sitkFloat32)

ROI_image.SetOrigin=origin
ROI_image.SetSpacing=space
ROI_image.SetDirection=direction

print(ROI_image.GetOrigin())
print(ROI_image.GetSpacing())
print(ROI_image.GetDirection())

print(moving_image.GetOrigin())
print(moving_image.GetSpacing())
print(moving_image.GetDirection())

The output is:

(0.0, 0.0, 0.0)
(1.0, 1.0, 1.0)
(-1.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 1.0)
(0.0, 0.0, 0.0)
(1.7200000286102295, 1.7200000286102295, 1.7200000286102295)
(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0)

Why is this happening? How to fix this?

Hello @debapriya,

The person who should know why this is happening is you, as this is a question about your inputs, not about any processing of them. How was the ROI image created and how was it written to disk?

Your code is incorrect, in terms of Python.

ROI_image.SetOrigin=origin
ROI_image.SetSpacing=space
ROI_image.SetDirection=direction

This overrides functions with data (ROI_image.SetX are functions).

The way to copy the metadata information is:

moving_image = sitk.ReadImage("Coreg/Data1/Moving/mpragegad_reg_reg.nii",sitk.sitkFloat32)

# don't read ROI_image as float, this is a label image
ROI_image = sitk.ReadImage("Coreg/Data1/intense100.nii") 

# copy the metadata from the moving_image to the ROI_image
ROI_image.CopyInformation(moving_image)
1 Like

It finally worked. Including proper meta-data did the job. I should have checked it earlier. Since the source of the other images and the ROI image was same, I assumed they all had same meta-data. Thanks for all the help.

1 Like

Hey @zivy, I agree with you.

In my thought match shape means when two arbitrary shapes having same kind of features in both the direction X and Y.

Or if you want to know in detail, visit this :point_right: What shape is a match box? because I am also not having that much clarification about that.