Resample overlaid volume

Good afternoon,

Imagine I have two volumes of images in 3D. Each one has its own “image spacing” and its own “image dimensions”.
However, I would like to overlay them in order to see if the organ on the first volume (let say the background) can fit with the organ on the second volume (let say the foreground).
On my python script, I load the first volume in “.nii” and display it then, I load the second one and display it.
Finally, I write that to overlay them together :

lm = slicer.app.layoutManager()
for sliceViewName in lm.sliceViewNames():
  sliceWidget = lm.sliceWidget(sliceViewName)
  view = lm.sliceWidget(sliceViewName).sliceView()
  sliceNode = view.mrmlSliceNode()
  sliceLogic = slicer.app.applicationLogic().GetSliceLogic(sliceNode)
  compositeNode = sliceLogic.GetSliceCompositeNode()
				# Setup background volume
  compositeNode.SetBackgroundVolumeID(self.VolumeNode1.GetID())
				# Setup foreground volume
  compositeNode.SetForegroundVolumeID(self.VolumeNode2.GetID())
				# Changer l'opacite
  compositeNode.SetForegroundOpacity(0.7)

I have tried the “Resample Scalar Volume” with an interpolation of nearestNeighbor and the spacing (the smallest one of the two volumes) but I can’t find how to visualize the two volumes overlaid (the one with no modification and the new second one) and write it in Python (I can’t find the python code on github for the module “Resample Scalar Volume”). Moreover, I need to change the “image dimensions” of the one that is resampled but I don’t know how to do that…

Does anyone have an idea on how can I do all of that ?
Thanks a lot in advance
Laura

Slicer displays volumes correctly in their physical location (defined by image origin, spacing, and axis directions). It is not necessary to manually resample them.

Does everything work well when you set the foreground/background volume using the graphical user interface?
Are the foreground and background volumes spatially registered to each other?

Good morning,
When I display one by one, the visualisation is ok, I can see all the slices in all plans
However, when I try to overlay the two, it isn’t well overlaid as you can see :
superposition
So I would like either being able to move one image from another to fit them correctly either resample them with the same dimensions and same spacing
What can I do ?
Thanks a lot
Laura

You don’t need to worry about resampling or dimensions, since Slicer can correctly overlay images with arbitrary non-matching geometry. However, you have to make sure the images are spatially registered to each other in physical space.

How these images are created?
Would you expect them to be spatially aligned (registered) in physical space?

Thanks to answer me !
At the very beginning, I have :

  • volume n°1 initial that is segmented by different treatments and that saved in ‘.nii’ so the format of the segmented image is the same as the initial one
  • volume n°2 initial (which has dimensions and spacing different from the volume n°1) is segmented with others treatments and saved in ‘.nii’ so the format of the segmented volume n°2 is the same as the initial one

I would expect to overlay the two segmentations let’s say an organ overlaid with a cavity for instance. So, i would like that the white parts of each volume (ie the segmented areas) be overlaid to see if it can fit together.
So, that’s why I think that I have to do something special because it is impossible to overlay two volumes that have different dimensions and spacing, isn’t it ?
I don’t know if it is more clear…
Thanks !

Yes, you need to spatially register the anatomical images. Result of registration is a transform that you can use to align segmentations. I would recommend to use SlicerElastix extension for registration, as it usually works well with default settings.

Oh thanks ! I have tried and I think that I am on the right way but is it normal to get that kind of image as output volume ? :
elastic
It seems really strange when I change the slice I look
A little more question : is it possible to create a little window pop-up with this module General Registration Elastix in my python script ?
Thanks a lot for your help !

I forgot to precise that the two volumes are not from the same patient, it is two different patients…

As long as images contain approximately the same anatomical region, registration of different patients should be successful.