> Dear SPM'ers,
>
> I used the function "spm_mireg.m" for registering two images, from the
> Matlab workspace.
> I got the six parameters that describe the rigid transformation , but I
> dont't know where to get from the *.mat file that contains the matrix of
> the rigid transformation that register the two images.
>
> Thank you for the answer,
>
> Nicoleta
Salut,
One easy way of doing this is using the spm_mireg_ui wrapper, which sets the
mat files for you, but I imagine you had some reason to use the spm_mireg
routine itself. In any case, the relevant code is in spm_mireg_ui:
x = spm_mireg(mireg(i).VG, mireg(i).VF);
M = inv(spm_matrix(x));
MM = zeros(4,4,size(mireg(i).PO,1));
for j=1:size(mireg(i).PO,1),
MM(:,:,j) = spm_get_space(deblank(mireg(i).PO(j,:)));
end;
for j=1:size(mireg(i).PO,1),
spm_get_space(deblank(mireg(i).PO(j,:)), M*MM(:,:,j));
end;
So, spm_mireg returns the (usually) 6 parameters (translations, rotations)
necessary to convert from mm space coordinates in the template image (VG) to mm
space in the source image (VF). spm_matrix converts this into a 4x4
transformation matrix, and the inverse gives the matrix that converts the
coordinates in the opposite direction. To get a new mat file for the source
image, you simply multiply the mat file for the image by the resulting matrix
M.
Thus:
x = spm_mireg(spm_vol('template.img')), spm_vol('source.img'));
M = inv(spm_matrix(x));
spm_get_space('source.img', M*spm_get_space('source.img'));
If you want the full voxel to voxel transformation matrix, from source voxels
to template voxels:
templateMat = spm_get_space('template.img');
sourceMat = spm_get_space('source.img');
voxtrans = inv(templateMat) * M * sourceMat;
Best,
Matthew
|