Try the attached function, which I think should also work for SPM5....
% Determine corresponding co-ordinate in un-normalised image.
% FORMAT orig_coord = get_orig_coord2(coord, matname,PU)
% coord - [x1 y1 z1 ; x2 y2 z2 ; etc] in MNI space (mm).
% matname - File containing transformation information (_sn.mat).
% PU - Name of un-normalised image
% orig_coord - Co-ordinate in un-normalised image (voxel).
%
% FORMAT orig_coord = get_orig_coord2(coord, matname)
% coord - [x1 y1 z1 ; x2 y2 z2 ; etc] in MNI space (mm).
% matname - File containing transformation information (_sn.mat).
% orig_coord - Original co-ordinate (mm).
You can use spm_get_space to convert between voxel and mm coordinates.
Best regards,
-John
On Wednesday 16 January 2008 12:44, Joao Pereira wrote:
> Hello,
>
> I'm currently trying to measure the location of fiducial points in mwc1
> images. Fiducials are extracted from the original image, which is then
> segmented; the corresponding coordinates of those fiducial points in the
> normalised segment would then be extracted. The original scan is
> 256x209x256 (0.86mm isotropic) and the final segment is standard 91x109x91
> (2mm isotropic), both rotated to match a compatible orientation.
>
> My issue is that I can't seem to get this work: I'm using the
> fname_seg_sn.mat file as an input for the registration parameters, together
> with code extracted from the spm_write_sn.m script (see below). Somehow,
> the coordinates in the resulting segment bear no relation to the original
> fiducials.
>
> load(fname_sn);
>
> flags2 = struct('wrap',[0 0 0],'interp',1,'vox',[NaN NaN NaN],...
> 'bb',ones(2,3)*NaN,'preserve',0);
>
> def_flags = struct('interp',1,'vox',NaN,'bb',NaN,'wrap',[0 0
> 0],'preserve',0);
> [def_flags.bb, def_flags.vox] = bbvox_from_V(VG(1));
>
> fnms = fieldnames(def_flags);
> for i=1:length(fnms),
> if isfield(flags2,fnms{i}),
> flags2.(fnms{i}) = def_flags.(fnms{i});
> end;
> end;
>
> [x,y,z,mat] = get_xyzmat(VG,flags2.bb,flags2.vox);
>
> [X,Y] = ndgrid(x,y);
> BX = spm_dctmtx(VG(1).dim(1),size(Tr,1),x-1);
> BY = spm_dctmtx(VG(1).dim(2),size(Tr,2),y-1);
> BZ = spm_dctmtx(VG(1).dim(3),size(Tr,3),z-1);
>
>
> point = norm_points{i}; %Extracts original fiducial
> coordinates, normalised (and rounded) to 91x109x91 space
>
> spm_point = [0 0 0];
>
> x = point(1); %sagital (91)
> y = point(2); %coronal (109)
> z = point(3); %axial (91)
>
> tx = get_2Dtrans(Tr(:,:,:,1),BZ,z);
> ty = get_2Dtrans(Tr(:,:,:,2),BZ,z);
> tz = get_2Dtrans(Tr(:,:,:,3),BZ,z);
> X1 = X + BX*tx*BY';
> Y1 = Y + BX*ty*BY';
> Z1 = z + BX*tz*BY'; %z=z(j)
> [X2,Y2,Z2] = mmult(X1,Y1,Z1,mat\VF.mat*Affine); %Could it be
> that mat or VF.mat are wrong?...
>
> spm_point(1) = X2(x,y); %Are these coordinates in the right
> order?
> spm_point(2) = Y2(x,y); % "
> spm_point(3) = Z2(x,y); % "
>
> I would appreciate any advice you can give me.
>
> Thank you very much in advance!
>
> Best,
>
> Joao Pereira
|