Transform coordinate of vertex points on an individual brain to those on the MNI starndard brain. MNI coordinate as well as Talairach coordinate corresponding to 'V' are returned. This routine requires SPM spatial normalization file. -- Usage [XYZmni , XYZtal, dd, IMGinfo] = vb_calc_mni_coord(parm) -- Input (Fields in 'parm' struct) brainfile : Subject brain file mask_file : Mask image file snfile : Created by SPM normalization (Personal-> MNI-template). The normalize transformation is contained. -- Output XYZmni : MNI coordinate (unit:m) [Nveretex * 3] XYZtal : Talairach coordinate (unit:m) [Nveretex * 3] dd : minimum error distance between 'V' and points on the MNI standard brain IMGinfo : -- Function required spm_dctmtx : vb_unsn : back transformation (by Gohda-san) --- NOTE 1 ---- When using the normalize transformation created by 'spm99', it is observed that x (Left-Right) coordinates are a little shifted after back-transformation in this routine. It is highly recommended to recalculate the normalize transformation by spm2 !!! --- NOTE 2 ---- Flip can not be considered in this routine. 2005/03/03 OY 2005/03/28 modified 2005/04/21 second part modified 2005/09/09 ver.030b compatible 2005/12/22 M.Sato 2006/2/3 M.Sato 2007/03/05 OY * input and output arguments are modified. * no save in this routine. * comment are modified. 2008-12-19 Taku Yoshioka Return 'pXYZmni' 2009-01-05 Taku Yoshioka Add parameter 'dxyz' for offset of standard brain mask. Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [XYZmni , XYZtal, dd, IMGinfo, pXYZmni] = vb_calc_mni_coord(parm) 0002 % Transform coordinate of vertex points on an individual brain to those on the MNI starndard brain. 0003 % 0004 % MNI coordinate as well as Talairach coordinate corresponding to 'V' are 0005 % returned. This routine requires SPM spatial normalization file. 0006 % 0007 % -- Usage 0008 % [XYZmni , XYZtal, dd, IMGinfo] = vb_calc_mni_coord(parm) 0009 % 0010 % -- Input (Fields in 'parm' struct) 0011 % brainfile : Subject brain file 0012 % mask_file : Mask image file 0013 % snfile : Created by SPM normalization (Personal-> MNI-template). 0014 % The normalize transformation is contained. 0015 % 0016 % -- Output 0017 % XYZmni : MNI coordinate (unit:m) [Nveretex * 3] 0018 % XYZtal : Talairach coordinate (unit:m) [Nveretex * 3] 0019 % dd : minimum error distance between 'V' and points on the MNI standard brain 0020 % IMGinfo : 0021 % 0022 % -- Function required 0023 % spm_dctmtx : 0024 % vb_unsn : back transformation (by Gohda-san) 0025 % 0026 % --- NOTE 1 ---- 0027 % When using the normalize transformation created by 'spm99', it is observed that 0028 % x (Left-Right) coordinates are a little shifted after back-transformation in this routine. 0029 % It is highly recommended to recalculate the normalize transformation by 0030 % spm2 !!! 0031 % --- NOTE 2 ---- 0032 % Flip can not be considered in this routine. 0033 % 0034 % 2005/03/03 OY 0035 % 2005/03/28 modified 0036 % 2005/04/21 second part modified 0037 % 2005/09/09 ver.030b compatible 0038 % 2005/12/22 M.Sato 0039 % 2006/2/3 M.Sato 0040 % 2007/03/05 OY 0041 % * input and output arguments are modified. 0042 % * no save in this routine. 0043 % * comment are modified. 0044 % 2008-12-19 Taku Yoshioka 0045 % Return 'pXYZmni' 0046 % 2009-01-05 Taku Yoshioka 0047 % Add parameter 'dxyz' for offset of standard brain mask. 0048 % 0049 % Copyright (C) 2011, ATR All Rights Reserved. 0050 % License : New BSD License(see VBMEG_LICENSE.txt) 0051 0052 mask_file = parm.mask_file; 0053 brainfile = parm.brainfile; 0054 snfile = parm.snfile; 0055 0056 % Max radius to check minimum distance to corresponding point [mm] 0057 if isfield(parm,'Rlimit') 0058 Rlimit = parm.Rlimit; 0059 else 0060 Rlimit = 4; 0061 end 0062 0063 % Max radius to search corresponding point [mm] in the 1st-step 0064 if isfield(parm,'Rmax') 0065 Rmax = parm.Rmax; 0066 else 0067 Rmax = 2; 0068 end 0069 0070 % In the 1st-step, nearest point is searched within Rmax 0071 % In the 2nd-step, nearest point is searched for all candidates 0072 % This value determine, efficiency of search, 0073 % but does not change the result 0074 0075 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0076 %%%%%%%%%%%%%%%%%%%% Don't modify %%%%%%%%%%%%%%%%%%%%%%%%%%% 0077 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0078 0079 %%% 0080 %%% Backward coordinate transformation 0081 %%% from the template brain to a subject's brain 0082 %%% Template file is neurological format (right handed spm). 0083 0084 % 0085 % Load subject brain coordinate 0086 % 0087 [V]=vb_load_cortex(brainfile); % [m] 0088 Npoint = size(V,1); 0089 0090 % Read image-header 0091 [dim, Trans, XYZmni] = vb_get_image_info(mask_file); 0092 IMGinfo.dim = dim; 0093 IMGinfo.mat = Trans; 0094 % dim(1:3) - the x, y and z dimensions of the volume 0095 % Trans - a 4x4 affine transformation matrix mapping from 0096 % voxel coordinates to MNI-mm-coordinates 0097 % XYZmni - 3 x n matrix of XYZ locations 0098 % mm-coordinates in atlas-template (origin : MNI-space origin) 0099 0100 % Read atlas-template image 0101 % Z - 3D image data 0102 0103 avw = avw_img_read(mask_file); 0104 Z = avw.img; 0105 0106 % Extract mask region 0107 Z = Z(:); 0108 mni_id = find(Z ~= 0); 0109 Z = Z(mni_id); 0110 0111 % mm-coordinates in atlas-template for brain region 0112 XYZmni = XYZmni(:,mni_id); 0113 0114 fprintf('# of template points = %d\n',length(mni_id)) 0115 fprintf('--- Back transformation to subject-image \n'); 0116 0117 % Back transformation to subject image 0118 sn = load(deblank(snfile)); 0119 [pXYZmni] = vb_unsn(XYZmni,sn); 0120 %[pXYZmni,flip_flag] = vb_unsn_for_mask(XYZmni,sn); 0121 0122 XYZmni = XYZmni'; % mm-coordinates in atlas-template (MNI-coordinate) 0123 pXYZmni = pXYZmni'; % mm-coordinates in subject image 0124 0125 %if flip_flag, 0126 % XYZmni(:,1) = -1*XYZmni(:,1); 0127 %end 0128 0129 % Offset 0130 if isfield(parm,'dxyz'), 0131 pXYZmni = pXYZmni+repmat(parm.dxyz,[size(pXYZmni,1) 1]); 0132 end 0133 0134 % if coordinate system is left-handed spm, flip x-direction coordinate 0135 % pXYZmni(:,1) = -pXYZmni(:,1) ; 0136 0137 %%% 0138 %%% Map MNI-coordinate to individual's cortical surface 0139 %%% 0140 0141 fprintf('--- Mapping MNI-coordinate onto a cortical surface of a subject-brain \n'); 0142 0143 % Find nearest point in atlas for each vertex 'V' 0144 [indx, dd] = vb_find_nearest_point(pXYZmni, V*1000, Rmax, 100, 1, 1); 0145 %figure; 0146 %plot3(V(:,1)*1000,V(:,2)*1000,V(:,3)*1000,'r.'); 0147 %hold on; 0148 %plot3(pXYZmni(:,1),pXYZmni(:,2),pXYZmni(:,3),'b.'); 0149 0150 % Map template-coordinate to subject cortex 0151 % XYZmni : MNI-coordinate corresponding to V(:,1:3) 0152 XYZmni = XYZmni(indx,:); 0153 0154 % Number of points whose minimum distance is less than Rlimit 0155 ix_match = find( dd <= Rlimit ); 0156 Nmatch = length(ix_match); 0157 0158 % mni2tal : MNI to Talairach coordinate transformation 0159 XYZtal = mni2tal(XYZmni); 0160 0161 % IMGinfo.dim(1:3) - the x, y and z dimensions of the volume 0162 % IMGinfo.mat - a 4x4 affine transformation matrix mapping from 0163 % voxel coordinates to real world coordinates. 0164 0165 % Voxel coordinate in maask_file image 0166 % XYZvox = inv(IMGinfo.mat) * [XYZmni'; ones(1,Npoint)]; 0167 % XYZvox = XYZvox(1:3,:)'; 0168 0169 % Check inverse-affine transformation 0170 % XYZmni2 = IMGinfo.mat * [XYZvox'; ones(1,Npoint)]; 0171 % err = sum(sum(abs(XYZmni-XYZmni2(1:3,:)')))/sum(sum(abs(XYZmni))) 0172 0173 fprintf('# of cortex points = %d\n',Npoint) 0174 fprintf('# of points ( d <= %3.0f mm ) = %d\n',Rlimit,Nmatch) 0175 fprintf('# of points ( d > %3.0f mm ) = %d\n',Rlimit,Npoint - Nmatch) 0176 fprintf('dmax = %4.1f mm \n', max(dd)) 0177 0178 xmax = max(XYZtal); 0179 xmin = min(XYZtal); 0180 0181 0182 XYZtal = XYZtal/1000; % mm -> m 0183 XYZmni = XYZmni/1000; % mm -> m 0184 dd = dd / 1000; % mm -> m 0185 0186 fprintf('[Xmax, Ymax, Zmax] = %6.1f %6.1f %6.1f\n',xmax) 0187 fprintf('[Xmin, Ymin, Zmin] = %6.1f %6.1f %6.1f\n',xmin) 0188 0189