Print

Print


Dear Kaveh,

I assume, that the 3D volume you are referring to is the data matrix, is that correct? In that case, the transformation matrix describes the orientation of that matrix in the "world space". What you usually want to do, is to transform a coordinate from "voxel space" in "world space" or vice-versa. Consider below script; it let's you choose two images, coregisters the second to the first and does some transformations. The transformation from "voxel" to "world" is done by multiplying the transformation matrix with the coordinate in "voxel" space. The transformation from "world" to "voxel" is done by inverting the matrix, then multiplying it with the coordinates in "world" space.
Mapping across two images requires an additional transformation matrix which maps from "world" of the first image to "world" of the second image.

Try 'help spm_matrix' if you wish learn more about the transformation matrix in order to construct your own or manipulate an existing transformation matrix.

%% Load two images, one per dialog
S=spm_vol(spm_select([1 1],'image','Select fixed image ..'));
F=spm_vol(spm_select([1 1],'image','Select moving image ..'));

%% Check Mappings
% Convert world (S) into voxel (S) and back
Smm = [3.0 16.8 4.8 1]'; % that's just an example
Svx=S.mat\Smm; % world to voxel
Smm = S.mat*Svx; % voxel to world, this should give  [3.0 16.8 4.8 1]'

%% coregister F to S
C = spm_coreg(S,F,{}); C = spm_matrix(C(:)');

%% Coordinates after Realignment
% world (S) to world (F)
Fmm = C*Smm;
% world (F) to voxel (F)
Fvx = F.mat\Fmm;

Bests,
Ahmed
--
Ahmed Abdulkadir, Student Assistant
Functional Brain Imaging (FBI)
Department of Neurology
University Medical Center Freiburg
Breisacher Str. 64, 79106 Freiburg

Phone: +49 (0) 761 270-54797
Fax:      +49 (0) 761 270-54819

On Jan 22, 2012, at 2:46 AM, Kaveh Vejdani wrote:

> Can someone please teach me how to apply a transformation matrix to a 3D volume?
> 
> Thanks,
> 
> Kaveh
>