0001 function [Vindex] = vb_extract_cortex(V0L,F0L,V0R,F0R,brain_parm,plot_mode)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 if ~exist('plot_mode', 'var')
0023 plot_mode = 0;
0024 end
0025
0026 NL = size(V0L,1);
0027 NR = size(V0R,1);
0028 NV = NL + NR;
0029
0030
0031 [VL,VLix] = load_cortex_label(brain_parm.FS_left_label_file);
0032 [VR,VRix] = load_cortex_label(brain_parm.FS_right_label_file);
0033
0034
0035 flgL = zeros(NL,1);
0036 flgR = zeros(NR,1);
0037
0038 flgL(VLix) = 1;
0039 flgR(VRix) = 1;
0040
0041 izL = find(flgL == 0);
0042 izR = find(flgR == 0);
0043
0044
0045 [IZL] = vb_connected_vertex(izL,F0L);
0046 [IZR] = vb_connected_vertex(izR,F0R);
0047
0048 izL = IZL{1};
0049 izR = IZR{1};
0050
0051
0052 flgL = zeros(NL,1);
0053 flgR = zeros(NR,1);
0054
0055 flgL(izL) = 1;
0056 flgR(izR) = 1;
0057
0058 icL = find(flgL == 0);
0059 icR = find(flgR == 0);
0060
0061 Vindex.cortexL = icL;
0062 Vindex.cortexR = icR;
0063 Vindex.corpusL = izL;
0064 Vindex.corpusR = izR;
0065
0066 NCL = length(icL);
0067 NCR = length(icR);
0068 NZL = length(izL);
0069 NZR = length(izR);
0070
0071
0072
0073
0074 fprintf('N_original = %d (left) %d (right)\n', NL,NR)
0075 fprintf('N_cortex = %d (left) %d (right)\n', NCL,NCR)
0076 fprintf('N_non_cortex = %d (left) %d (right)\n', NZL,NZR)
0077
0078 if plot_mode == 0, return; end;
0079
0080
0081 FLz = vb_patch_select(izL,F0L,NL);
0082 FRz = vb_patch_select(izR,F0R,NR);
0083
0084 figure;
0085 subplot(1,2,1)
0086 vb_plot_surf(V0L,F0L,'','b')
0087 hold on
0088 vb_plot_surf(V0L,FLz,'r','r')
0089
0090 subplot(1,2,2)
0091 vb_plot_surf(V0R,F0R,'','b')
0092 hold on
0093 vb_plot_surf(V0R,FRz,'r','r')
0094
0095
0096
0097
0098 function [V,Vix,Vlabel] = load_cortex_label(ascfile)
0099
0100
0101 fid = fopen(ascfile,'r');
0102 fgetl(fid);
0103
0104 Num = fscanf(fid,'%d',1);
0105
0106
0107 NV = Num(1);
0108
0109
0110 data = fscanf(fid,'%d %e %e %e %e',inf);
0111
0112 fclose(fid);
0113
0114
0115
0116 V = reshape(data(1:NV*5),[5 NV])';
0117
0118 Vix = V(:,1) + 1;
0119 Vlabel = V(:,5);
0120 V = V(:,2:4);