0001 function [Atlas] = vb_correct_atlas_label_LR(Atlas,brainfile,Para)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 if ~exist('Para','var'), Para = []; end
0026
0027
0028 if isfield(Para,'Rlabel')
0029 Rmax = Para.Rlabel;
0030 else
0031 Rmax = 0.012;
0032 end
0033
0034 if isfield(Para,'rate')
0035 rate = Para.rate;
0036 else
0037 rate = 0.1;
0038 end
0039
0040
0041 [V, F] = vb_load_cortex(brainfile);
0042
0043
0044 NL = F.NdipoleL;
0045 FL = F.F3L;
0046 FR = F.F3R;
0047 NV = size(V,1);
0048
0049 name = Atlas.label_name ;
0050 label = Atlas.label ;
0051 Narea = length(label);
0052
0053
0054 Label = [];
0055 Name = [];
0056 Lid = 0;
0057 Rid = max(label)+10;
0058 Lext = '_L';
0059 Rext = '_R';
0060
0061
0062 xxP = Atlas.xxP;
0063 xxQ = zeros(NV,1);
0064
0065 Num = sum( xxP == 0 );
0066 fprintf('--- Unlabeled vertex = %d\n',Num)
0067 fprintf('--- Find connected region\n')
0068
0069 id = 0;
0070
0071 for n=1:Narea
0072
0073 ix = find( xxP == label(n) );
0074
0075 if isempty(ix), continue; end;
0076
0077
0078
0079
0080
0081 ixL = ix( ix <= NL );
0082 [Vindx, Nall] = vb_connected_vertex(ixL,FL);
0083
0084
0085 if ~isempty(Vindx)
0086 jj = find( Nall >= Nall(1)*rate );
0087 xxQ([Vindx{jj'}]) = label(n) + Lid;
0088 end
0089 id = id + 1;
0090 Label(id) = label(n) + Lid;
0091 Name{id} = [name{n} Lext];
0092
0093
0094
0095
0096
0097 ixR = ix( ix > NL );
0098 [Vindx, Nall] = vb_connected_vertex(ixR,FR);
0099
0100
0101 if ~isempty(Vindx)
0102 jj = find( Nall >= Nall(1)*rate );
0103 xxQ([Vindx{jj'}]) = label(n) + Rid;
0104 end
0105 id = id + 1;
0106 Label(id) = label(n) + Rid;
0107 Name{id} = [name{n} Rext];
0108
0109 end
0110
0111 fprintf('--- Morphological smoothing\n')
0112
0113
0114 Narea = length(Label);
0115
0116
0117 ixfix = find( xxQ == 0 );
0118 Nfix = length(ixfix);
0119
0120
0121 PP = zeros(Nfix,Narea);
0122
0123
0124 W = vb_spatial_gauss_filter(brainfile,Rmax,Rmax,[1:NV]);
0125 W = W(ixfix,:);
0126
0127 for n=1:Narea
0128
0129 ix = find( xxQ == Label(n) );
0130
0131 if isempty(ix), continue; end;
0132
0133 PP(:,n) = sum(W(:,ix), 2);
0134
0135 end
0136
0137 for n=1:Nfix
0138 [Pmax, id] = max(PP(n,:));
0139
0140 if Pmax > 0,
0141 xxQ(ixfix(n)) = Label(id);
0142 end
0143 end
0144
0145 Atlas.xxP = xxQ;
0146 Atlas.label = Label;
0147 Atlas.label_name = Name ;
0148
0149 Num = sum( xxQ == 0 );
0150 fprintf('--- Final unlabeled vertex = %d\n',Num)
0151
0152
0153
0154