======================================================================= 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). - or the structure containing the transformation. 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). - or the structure containing the transformation. orig_coord - Original co-ordinate (mm). ======================================================================= Copyright (C) 2005 Wellcome Department of Imaging Neuroscience
0001 function orig_coord = spm_get_orig_coord_spm5(coord, matname,PU) 0002 0003 %======================================================================= 0004 % Determine corresponding co-ordinate in un-normalised image. 0005 % FORMAT orig_coord = get_orig_coord2(coord, matname,PU) 0006 % coord - [x1 y1 z1 ; x2 y2 z2 ; etc] in MNI space (mm). 0007 % matname - File containing transformation information (_sn.mat). 0008 % - or the structure containing the transformation. 0009 % PU - Name of un-normalised image 0010 % orig_coord - Co-ordinate in un-normalised image (voxel). 0011 % 0012 % FORMAT orig_coord = get_orig_coord2(coord, matname) 0013 % coord - [x1 y1 z1 ; x2 y2 z2 ; etc] in MNI space (mm). 0014 % matname - File containing transformation information (_sn.mat). 0015 % - or the structure containing the transformation. 0016 % orig_coord - Original co-ordinate (mm). 0017 %======================================================================= 0018 % Copyright (C) 2005 Wellcome Department of Imaging Neuroscience 0019 0020 % John Ashburner 0021 % $Id: spm_get_orig_coord_spm5.m 1332 2011-02-24 06:57:20Z rhayashi $ 0022 0023 if ischar(matname) 0024 t = load(matname); 0025 elseif isstruct(matname) 0026 t = matname; 0027 else 0028 error('Wrong normalisation parameters!'); 0029 end 0030 0031 if size(coord,2)~=3, error('coord must be an N x 3 matrix'); end; 0032 coord = coord'; 0033 0034 Mat = inv(t.VG(1).mat); 0035 xyz = Mat(1:3,:)*[coord ; ones(1,size(coord,2))]; 0036 Tr = t.Tr; 0037 Affine = t.Affine; 0038 d = t.VG(1).dim(1:3); 0039 0040 if nargin>2, 0041 VU = spm_vol(PU); 0042 Mult = VU.mat\t.VF.mat*Affine; 0043 % disp('Output co-ordinates are in voxels'); 0044 else 0045 Mult = t.VF.mat*Affine; 0046 % disp('Output co-ordinates are in mm'); 0047 end; 0048 0049 if (prod(size(Tr)) == 0), 0050 affine_only = 1; 0051 basX = 0; tx = 0; 0052 basY = 0; ty = 0; 0053 basZ = 0; tz = 0; 0054 else, 0055 affine_only = 0; 0056 basX = spm_dctmtx(d(1),size(Tr,1),xyz(1,:)-1); 0057 basY = spm_dctmtx(d(2),size(Tr,2),xyz(2,:)-1); 0058 basZ = spm_dctmtx(d(3),size(Tr,3),xyz(3,:)-1); 0059 end; 0060 0061 if affine_only, 0062 xyz2 = Mult(1:3,:)*[xyz ; ones(1,size(xyz,2))]; 0063 else, 0064 xyz2 = zeros(3,size(xyz,2)); 0065 for i=1:size(xyz,2), 0066 bx = basX(i,:); 0067 by = basY(i,:); 0068 bz = basZ(i,:); 0069 tx = reshape(... 0070 reshape(Tr(:,:,:,1),size(Tr,1)*size(Tr,2),size(Tr,3))... 0071 *bz', size(Tr,1), size(Tr,2) ); 0072 ty = reshape(... 0073 reshape(Tr(:,:,:,2),size(Tr,1)*size(Tr,2),size(Tr,3))... 0074 *bz', size(Tr,1), size(Tr,2) ); 0075 tz = reshape(... 0076 reshape(Tr(:,:,:,3),size(Tr,1)*size(Tr,2),size(Tr,3))... 0077 *bz', size(Tr,1), size(Tr,2) ); 0078 xyz2(:,i) = Mult(1:3,:)*[xyz(:,i) + [bx*tx*by' ; bx*ty*by' ; bx*tz*by']; 1]; 0079 end; 0080 end; 0081 orig_coord = xyz2'; 0082 0083 return;