vb_atlas2vb create an areafile based on the anatomical atlas ---- Syntax vb_atlas2vb(parm) ---- Input (Field names in 'parm') atlas_id : ID of atlas. atlas_text : atlas label name text file atlas_file : atlas image file save_areafile : Area file saved save_atlasfile : Atlas file saved brainfile : brain file; --- Function required explode : string manupilation ---- NOTE ----- When using the normalize transformation matrix created by 'spm99', back transformation results with a little shift toward X(Left-Right) direction compared with brain file. It is highly recommended to recalculate the transformation matrix by spm2 !!! 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 2006/11/14 M.Sato 2007/03/05 OY * MNI coordinate is stored in brainfile. * save_xyzfile is removed. * A label for 'Corpus' is NaN. 2009-01-05 Taku Yoshioka Supression of confirmation dialog Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function vb_atlas2vb(parm) 0002 % vb_atlas2vb create an areafile based on the anatomical atlas 0003 % 0004 % ---- Syntax 0005 % vb_atlas2vb(parm) 0006 % 0007 % ---- Input (Field names in 'parm') 0008 % atlas_id : ID of atlas. 0009 % atlas_text : atlas label name text file 0010 % atlas_file : atlas image file 0011 % save_areafile : Area file saved 0012 % save_atlasfile : Atlas file saved 0013 % brainfile : brain file; 0014 % 0015 % --- Function required 0016 % explode : string manupilation 0017 % 0018 % ---- NOTE ----- 0019 % When using the normalize transformation matrix created by 'spm99', 0020 % back transformation results with a little shift 0021 % toward X(Left-Right) direction compared with brain file. 0022 % It is highly recommended to recalculate 0023 % the transformation matrix by spm2 !!! 0024 % 0025 % 2005/03/03 OY 0026 % 2005/03/28 modified 0027 % 2005/04/21 second part modified 0028 % 2005/09/09 ver.030b compatible 0029 % 2005/12/22 M.Sato 0030 % 2006/2/3 M.Sato 0031 % 2006/11/14 M.Sato 0032 % 2007/03/05 OY 0033 % * MNI coordinate is stored in brainfile. 0034 % * save_xyzfile is removed. 0035 % * A label for 'Corpus' is NaN. 0036 % 2009-01-05 Taku Yoshioka 0037 % Supression of confirmation dialog 0038 % 0039 % Copyright (C) 2011, ATR All Rights Reserved. 0040 % License : New BSD License(see VBMEG_LICENSE.txt) 0041 atlas_id = parm.atlas_id; 0042 atlas_text = parm.atlas_text; 0043 atlas_file = parm.atlas_file; 0044 brainfile = parm.brainfile; 0045 0046 save_areafile = parm.save_areafile; 0047 save_atlasfile = parm.save_atlasfile; 0048 0049 % Max radius to check minimum distance to corresponding point [mm] 0050 if isfield(parm,'Rlimit') 0051 Rlimit = parm.Rlimit; 0052 else 0053 Rlimit = 4; 0054 end 0055 0056 % Max radius to search corresponding point [mm] in the 1st-step 0057 if isfield(parm,'Rmax') 0058 Rmax = parm.Rmax; 0059 else 0060 Rmax = 2; 0061 end 0062 0063 % In the 1st-step, nearest point is searched within Rmax 0064 % In the 2nd-step, nearest point is searched for all candidates 0065 % This value determine, efficiency of search, 0066 % but does not change the result 0067 0068 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0069 %%%%%%%%%%%%%%%%%%%% Don't modify %%%%%%%%%%%%%%%%%%%%%%%%%%% 0070 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0071 0072 %%% Template file is neurological format (right handed spm). 0073 0074 % ----- Corpus label 0075 corpus_key = 'Corpus'; 0076 corpus_label = NaN; 0077 0078 % 0079 % ---- Load MNI-mm-coordinate for subject brain (should be calculated before) 0080 % 0081 warning('off', 'MATLAB:load:variableNotFound'); 0082 load(brainfile, 'Vmni','derr'); 0083 warning('on', 'MATLAB:load:variableNotFound'); 0084 if ~exist('derr', 'var'), derr = zeros(size(Vmni,1), 1); end 0085 XYZmm = Vmni*1000; % mm 0086 dd = derr*1000; % mm 0087 Npoint = size(XYZmm,1); 0088 Vlabel = zeros(Npoint,1); 0089 dd_label = zeros(Npoint,1); 0090 0091 Vindx = [1:Npoint]; 0092 % % 0093 % % ----- Remove corpus 0094 % % 0095 % fprintf('--- Remove corpus region\n'); 0096 % [Vindx, Iremove] = vb_remove_corpus_run(brainfile); 0097 % Vlabel(Iremove) = corpus_label; 0098 % 0099 % fprintf('# of Corpus points = %d\n',length(Iremove)) 0100 0101 % Read image-header 0102 [dim, Trans, XYZmm0] = vb_get_image_info(atlas_file); 0103 0104 % Read atlas-template image 0105 % Z - 3D image data 0106 %Zlabel = read_image(atlas_file); 0107 0108 avw = avw_img_read(atlas_file); 0109 Zlabel = avw.img; 0110 0111 % Zlabel - 3D image data (label value) 0112 % XYZmm0 - 3 x n matrix of XYZ locations 0113 % mm-coordinates in atlas-template (origin : AC-PC center) 0114 Zlabel = Zlabel(:); 0115 0116 % Extract labeled region 0117 mni_id = find(Zlabel ~= 0); 0118 Zlabel = Zlabel(mni_id); 0119 % MNI-mm-coordinates in atlas-template for labeled region 0120 XYZmm0 = XYZmm0(:,mni_id)'; 0121 0122 fprintf('# of template points = %d\n',length(mni_id)) 0123 0124 fprintf('--- Mapping Atlas-label onto 2D cortical surface \n'); 0125 0126 % Find nearest labeled point in atlas 0127 [indx, dd_tmp] = vb_find_nearest_point(XYZmm0, XYZmm(Vindx,:), Rmax, 100, 0, 1); 0128 0129 fprintf('# of matched brain points = %d\n',length(indx)) 0130 0131 % Find points whose minimum distance to atlas brain region is less than Rlimit 0132 ix_match = find( dd(Vindx) <= Rlimit & dd_tmp < Rmax & indx > 0 ); 0133 %ix_match = find( dd(Vindx) <= Rlimit & dd_tmp < Rmax ); 0134 %ix_match = find( dd(Vindx) <= Rlimit ); 0135 0136 fprintf('# of close points = %d\n',length(ix_match)) 0137 0138 dd_label(Vindx) = dd_tmp; 0139 Vlabel(Vindx(ix_match)) = Zlabel(indx(ix_match)); 0140 0141 % Fill label for large distant point 0142 ixz = find( dd_label >= Rmax ); 0143 fprintf('# of unlabeld point = %d\n', length(ixz)) 0144 0145 %fprintf('Filling unlabeled points\n') 0146 %Vlabel = vb_fill_atlas_label(brainfile, Vlabel, ixz, Rlimit); 0147 0148 % 0149 % ---- Save labeled area 0150 % 0151 Nlabel = sum( Vlabel ~= 0 ); % # of labeled points 0152 fprintf('# of all vertex = %d\n',Npoint) 0153 fprintf('# of cortex points = %d\n',length(Vindx)) 0154 fprintf('# of labeled points = %d\n',Nlabel) 0155 0156 % Read atlas text file and extract area keys. 0157 [label, label_name] = vb_read_atlas_label(atlas_text); 0158 0159 % Add Corpus label 0160 Narea = length(label); 0161 label(Narea+1) = corpus_label; 0162 label_name{Narea+1} = corpus_key; 0163 0164 % Intensity of 'Act.xxP' is the label for each vertex 0165 Atlas.key = [atlas_id]; 0166 Atlas.xxP = Vlabel; 0167 Atlas.label = label; 0168 Atlas.label_name = label_name; 0169 Atlas.dd_label = dd_label; 0170 0171 % Save label as actfile 0172 fprintf('Save the atlas file as "%s" \n', save_atlasfile); 0173 vb_add_act(save_atlasfile,Atlas,[],false); 0174 0175 % Save area label into area file 0176 fprintf('Save the area file as "%s" \n', save_areafile); 0177 0178 vb_save_atlas_label(save_areafile,Vlabel,label,label_name); 0179 0180 clear Zlabel Vlabel XYZmm0 XYZmm Zlabel