nifty - apply transformation matrix without resampling

Questions about BrainVisa usage and installation

Moderators: denghien, riviere

Post Reply
Pauline Roca
Posts: 3
Joined: Mon Aug 29, 2011 10:36 am

nifty - apply transformation matrix without resampling

Post by Pauline Roca »

Hi,

Here is my problem.
I have two images in nifty format:
- one time of flight image (tof.nii, with a transformation matrix inside), 3D volume, with high resolution and a partial field of view
- one magnitude image (mag.nii), 3D volume in a lower resolution.
Using FSL ( FLIRT 2 times, with 3DOF and 6 DOF), I computed a transformation matrix (tof2mag.mat) and when looking at the resampled tof image (in the same resolution as mag.nii) it is ok, this registration worked well.

But I don't want to resample my tof image. I want to keep its high resolution, but changes the transformation matrix in the header (by composing the current transformation matrix I have by the tof2mag.mat). And in FSL I did not manage to do this...
Is there a way to do this in aims/pyaims or brainvisa ?

I tried in pyaims:
I converted the tof2mag.mat to .trm (using Brainvisa > Tools > Converters).
I load the tof image in pyaims:
tof = aims.read('tof.nii')
here is the current tof image transformation:
tof.header()['transformations']=
Out[24]: [ [ -0.999968945980072, 2.90168227365938e-05, 0.00788639020174742, 104.844856262207, 0.00112898182123899, -0.989195644855499, 0.146790638566017, 156.384750366211, -0.00780521612614393, -0.146799236536026, -0.989136099815369, 0.940803527832031, 0, 0, 0, 1 ] ]
I read the tof2mag.mat trm file:
tof2magtrm = aims.read('./tof2mag.trm') (type: soma.aims.AffineTransformation3d)
And then, I am blocked, I just don't know how to combine these two transformations...

Thanks a lot in advance for your help !!
User avatar
riviere
Site Admin
Posts: 1361
Joined: Tue Jan 06, 2004 12:21 pm
Location: CEA NeuroSpin, Saint Aubin, France
Contact:

Re: nifty - apply transformation matrix without resampling

Post by riviere »

Hi Pauline,

Just to be sure I understand what you did: you have used the "FSLtransformationToAims" process in Brainvisa ? With tof2mag.mat as 1st parameter, and tof.nii and mag.nii as source_volume and registered_volume ?
Have tou loaded the resulting transformation in Anatomist as the transformation between referentials assigned to tof and mag respectively ? (to check if the transform is OK)

Now how do you want to use the transformation ? Write it back in the source volume header, a bit like what SPM does ? You should just have to change/add the appropriate thansformation to the transformations / referentials fields and save the tof volume back. Now the question is: which transformation, to what other referential, do you need ?
If you insert the converted transform, it will go to the AIMS referential of the registered volume (mag). For Aims/Anatomist it's OK, but if you use another software/viewer it will probably not be the expected thing.
So maybe you can set a transform to the mag volume scanner-based referential (?) (I think this is what SPM does, not completely sure). In this case both images will provide a transformation to a common referential.
Then you have to combine the converted transformation with the the one in mag header:

Code: Select all

tof2magtrm = aims.read('tof2mag.trm')
mag = aims.read('mag.nii')
mag2scan = aims.AffineTransformation3d(mag.header()['transformations'][0])
tof2scan = mag2scan * tof2magtrm
tof.header()['transformations'].append(tof2scan.toVector())
tof.header()['referentials'].append('Coordinates aligned to another file or to anatomical truth')
aims.write(tof, 'tof_with_trans.nii')
The conversion can also be done in python if you want to do it in a script rather than using the BV process (it is actually in pyaims):

Code: Select all

from soma.aims import fslTransformation
trm = fslTransformation.fslMatToTrm('tof2mag.mat', 'tof.nii', 'mag.nii')
aims.write(trm, 'tof2mag.trm')
(In the source file of the fslTransformation module, there are extensive comments about what is done for the conversion)

Note: this comes with no warranty, blah blah... I have not tested the code I write here...

Denis
Post Reply