Spm.utils applytransform mat file description

Hi ,

Can someone tell me the description of each element in the matrix of input mat file for spm.utils applytransform

mat: (an existing file name)
file holding transform to apply

Its a 4*4 matrix , but nowhere I can find which element in the matrix corresponds to pitch,roll,yaw, xyz translation, scaling, affine .

Hi Sandeep,

Have a look at spm_matrix.m: given a parametrisation of an affine transformation, it will return the corresponding 4x4 transformation matrix. This is the function called if you enter “Reorientation Parameters” instead of “Reorientation Matrix”.

Best,
Guillaume.

thanks for the reply.

Hi ,

So I am using spm12 standalone and MCR, is it possible to call spm_matrix.m in nipype with this setup, it looks like there is no way to do that from my research online so far. Can you help me with a small script on how to do that.

Hi Sandeed,

it would be useful if you could provide more details about what you are trying to do as there might be several ways to achieve the same goal.

I don’t know how this would integrate with nipype but if you create a text file called transform.m containing:

mat = load(inputs{1});
spm_imatrix(mat.M)

you can use it with the Standalone SPM12 to load an affine transformation matrix from file and display its parametrisation:

spm12-matlab script transform.m reorient.mat

All the best,
Guillaume.

The spm functions do well with full version of matlab and nipype setup , but I can find a way to implement the spm functions with MCR and nipype setup.

So I currently am implementing VBM (basic steps: reorientation, segmentation, normalization, smoothing) on some structural t1w niftis and I am using nipype , MCR and spm12 standalone to achieve this. So my spm12 standalone uses Matlab common runtime in nipype.
from nipype.interfaces import spm
spm.SPMCommand.set_mlab_paths(
matlab_cmd=’/opt/spm12/run_spm12.sh /opt/mcr/v95 script’, use_mcr=True)
spm.SPMCommand().version

returns ‘12.7507’
and I am able to run my vbm pipeline fully just fine.

I currently pass reorientaion parameters like (x,y,z,pitch roll,yaw) in a .mat file as that is the only option which is given by the function nipype.interfaces.spm.utils.applytransform()

The goal is: I want to be able to pass reorientation parameters as arguments without needing a .mat file as input. The applytransform() does not allow that, so I am trying to implement the spm_imatrix() function as you said, but its implementation under MCR is not doable as of my knowledge. I know that custom spm functions under a regular matlab work fine, the problem is using MCR .

So if you can help , please let me know how to implement spm_imatrix() with MCR.

@Sandeep_Panta - i think we would need a little more info. but in general you can stick anything inside a function node. if you are trying to do this as part of a workflow, i would recommend that.

Say I want to implement spm_matrix.m function from spm12 standalone (using MCR) as a function node using nipype. Could you give me a sample script of that since I am not sure how to implement that. Should I expect the foll. script to work:

import nipype.pipeline.engine as pe
from nipype.interfaces.utility import Function
pe.Node(interface=Function(function=spm_matrix),name=‘test_spm’)