freesurfer_read_talxfm - Read FreeSurfer talairach.xfm file [TalairachXFM] = freesurfer_read_talxfm(file) This function will read an ascii file that contains the talairach transformation matrix for a FreeSurfer MRI volume. These files are located in <subject>/mri/transforms/talairach.xfm The transformation matrix is based on an affine coregistration of the FreeSurfer MRI volume with the MNI template volume. To use the TalairachXFM with a surface file, see freesurfer_surf2tal or just consider the following: Lets assume the surface RAS coordinates are in a vector, v = [R A S 1]', and the talairach.xfm matrix is X, then MNI Talairach coordinates are: vMNI = X * v;
0001 function [TalairachXFM] = freesurfer_read_talxfm(file) 0002 0003 % freesurfer_read_talxfm - Read FreeSurfer talairach.xfm file 0004 % 0005 % [TalairachXFM] = freesurfer_read_talxfm(file) 0006 % 0007 % This function will read an ascii file that contains the talairach 0008 % transformation matrix for a FreeSurfer MRI volume. These files are 0009 % located in <subject>/mri/transforms/talairach.xfm 0010 % 0011 % The transformation matrix is based on an affine coregistration of the 0012 % FreeSurfer MRI volume with the MNI template volume. To use the 0013 % TalairachXFM with a surface file, see freesurfer_surf2tal or just 0014 % consider the following: 0015 % 0016 % Lets assume the surface RAS coordinates are in a vector, 0017 % v = [R A S 1]', and the talairach.xfm matrix is X, then MNI Talairach 0018 % coordinates are: 0019 % 0020 % vMNI = X * v; 0021 % 0022 0023 % $Revision: 1.3 $ $Date: 2005/07/05 23:37:24 $ 0024 0025 % Licence: GNU GPL, no implied or express warranties 0026 % History: 11/2004 Darren.Weber_at_radiology.ucsf.edu 0027 % 0028 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0029 0030 ver = '$Revision: 1.3 $'; 0031 fprintf('FREESURFER_READ_TALXFM [v %s]\n',ver(11:15)); 0032 0033 fid = fopen(file,'r'); 0034 0035 if isequal(fid,-1), 0036 S=sprintf('Could not open file: "%s"',file); 0037 error(S); 0038 else 0039 0040 fprintf('...Reading FreeSurfer talairach.xfm file:\n...%s\n\n',file); 0041 0042 % read lines until we get the string 'Linear_Transform', which precedes 0043 % the data transformation matrix 0044 gotit = 0; 0045 string2match = 'Linear_Transform'; 0046 for i=1:20, % read up to 20 lines, no more 0047 temp = fgetl(fid); 0048 if strmatch(string2match,temp), 0049 % we have the right line, so don't read any more 0050 gotit = 1; 0051 break; 0052 end 0053 end 0054 0055 if gotit, 0056 % Read the transformation matrix (3x4). 0057 TalairachXFM = fscanf(fid,'%f',[4,3])'; 0058 TalairachXFM(4,:) = [0 0 0 1]; 0059 fclose(fid); 0060 else 0061 fclose(fid); 0062 error('failed to find ''Linear_Transform'' string in first 20 lines of xfm file.'); 0063 end 0064 0065 end 0066 0067 return