I want to apply in Matlab the 4x4 transformation matrix generated by FSL to a 3D image, to get the affine transformation field. Normally, to obtain the transformed coordinates you compute the matrix-vector product
y = Mx
where M is the transformation matrix, x are your coordinates and y are the transformed coordinates. I have tried this but I do not get the correct transformed image when following this approach. My coordinate system is a coordinate system where origo is the center of the image, the axes follow the right-hand matrix notation (positive x is negative cartesian y, positive y is positive cartesian x, z axis in increasing plane direction)
How can I apply the obtained transformation matrix obtained by FLIRT to these coordinates? Do I just need to convert to standard cartesian coordiantes?
My matlab code appears like this:
dim = [ 128 158 17]
% make grid
[x{1,1} x{2,1} x{3,1}] = ndgrid(1:dim(1),1:dim(2),1:dim(3));
C = [x{1}(:) x{2}(:) x{3}(:)]';
U = NaN(size(C));
% apply transformation
for i = 1 : size(C,2)
c = [C(:,i); 1];
u = omat*c;
U(:,i) = u(1:3);
end;
% convert back to image u1,u2,u3
u = cell(3,1);
for i = 1 : 3
u{i} = reshape(U(i,:),dim(1),dim(2),dim(3)) - x{i};
end;
Thank you,
Erlend Hodneland
|