Home > vbmeg > functions > tool_box > atlas2vb_dir > vb_atlas2vb_std.m

vb_atlas2vb_std

PURPOSE ^

vb_atlas2vb create an areafile based on the anatomical atlas

SYNOPSIS ^

function vb_atlas2vb_std(parm)

DESCRIPTION ^

 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)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function    vb_atlas2vb_std(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 
0042 atlas_id   = parm.atlas_id;
0043 atlas_text = parm.atlas_text; 
0044 atlas_file = parm.atlas_file; 
0045 brainfile  = parm.brainfile;
0046 
0047 save_areafile  = parm.save_areafile;
0048 save_atlasfile = parm.save_atlasfile;
0049 
0050 % Max radius to check minimum distance to corresponding point [mm]
0051 if    isfield(parm,'Rlimit')
0052     Rlimit = parm.Rlimit;
0053 else
0054     Rlimit = 4; 
0055 end
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 % Standard brain cortex in MNI-mm coordinate (origin in MNI-space)
0075 load(brainfile,'V','F')
0076 
0077 NL = F.NdipoleL;
0078 NP = size(V,1);
0079 Vlabel     = zeros(NP,1);
0080 
0081 % Read atlas-template image
0082 % Zlabel - label for 3D image data (label value)
0083 % XYZmm0 - 3 x n matrix of XYZ locations
0084 %          mm-coordinates in atlas-template (origin : AC-PC center)
0085 
0086 avw = avw_img_read(atlas_file);
0087 Zlabel = avw.img;
0088 
0089 % Read image-header
0090 [dim, Trans] = vb_get_image_info(atlas_file);
0091 
0092 % convert to standard voxcel coordinate from mm-coordinate
0093 Vox = [V*1000 ones(NP,1)] * inv(Trans');
0094 Vox = round(Vox(:,1:3));
0095 
0096 VL = Vox(1:NL,:);
0097 VR = Vox(1+NL:end,:);
0098 
0099 % Extract labeled left region
0100 mni_L = sub2ind(dim, VL(:,1), VL(:,2), VL(:,3) );
0101 mni_R = sub2ind(dim, VR(:,1), VR(:,2), VR(:,3) );
0102 
0103 label_L = Zlabel(mni_L);
0104 label_R = Zlabel(mni_R);
0105 
0106 fprintf('--- Mapping Atlas-label onto 2D cortical surface \n');
0107 
0108 % voxcel coordinate wuth label
0109 ix_label = find(Zlabel(:) > 0);
0110 [x,y,z] = ind2sub(dim,ix_label);
0111 Zlabel = Zlabel(ix_label);
0112 
0113 % Left non labeled points
0114 ixL = find( label_L == 0 );    
0115 % Find nearest labeled point in atlas
0116 [indx, dd] = vb_find_nearest_point([x,y,z], VL(ixL,:), Rmax, 100, 0, 1);
0117 % Find points whose minimum distance to atlas brain region is less than Rmax
0118 ix_match = find( dd < Rmax & indx > 0 );
0119 
0120 label_L(ixL(ix_match)) = Zlabel(indx(ix_match));
0121 
0122 % Right non labeled points
0123 ixR = find( label_R == 0 );    
0124 % Find nearest labeled point in atlas
0125 [indx, dd] = vb_find_nearest_point([x,y,z], VR(ixR,:), Rmax, 100, 0, 1);
0126 % Find points whose minimum distance to atlas brain region is less than Rmax
0127 ix_match = find( dd < Rmax & indx > 0 );
0128 
0129 label_R(ixR(ix_match)) = Zlabel(indx(ix_match));
0130 
0131 %
0132 % ---- Save labeled area
0133 %
0134 ix_L = find( label_L ~= 0 );    % # of labeled points
0135 ix_R = find( label_R ~= 0 );    % # of labeled points
0136 
0137 label_R(ix_R) = label_R(ix_R) + 1000;
0138 
0139 Vlabel(1:NL)     = label_L;
0140 Vlabel(1+NL:end) = label_R;
0141 
0142 % Read atlas text file and extract area keys.
0143 [label, label_name] = vb_read_atlas_label(atlas_text);
0144 
0145 % Save area label into area file
0146 fprintf('Save the area file as "%s" \n', save_areafile);
0147 
0148 label = [label , label + 1000];
0149 
0150 N = length(label_name);
0151 label_name2 = cell(2*N,1);
0152 
0153 for n = 1:N
0154     name = strrep(label_name{n},'brodmann area ','');
0155     label_name2{n}   = [name '_L'];
0156     label_name2{n+N} = [name '_R'];
0157 end    
0158 
0159 vb_save_atlas_label(save_areafile,Vlabel,label,label_name2);
0160 
0161 % Intensity of 'Act.xxP' is the label for each vertex
0162 Atlas.key = [atlas_id];
0163 Atlas.xxP = Vlabel;
0164 Atlas.label      = label;
0165 Atlas.label_name = label_name2;
0166 
0167 % Save label as actfile
0168 fprintf('Save the atlas file as "%s"  \n', save_atlasfile);
0169 vb_add_act(save_atlasfile,Atlas,[],false);
0170 
0171 fprintf('# of all vertex     = %d\n',NP)
0172 fprintf('# of left labeled points  = %d/%d\n',length(ix_L),NL)
0173 fprintf('# of right labeled points = %d/%d\n',length(ix_R),NP-NL)
0174 
0175 %clear Zlabel Vlabel XYZmm0 XYZmm Zlabel

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005