0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 S = 'c01';
0016
0017
0018 meshplot = 0;
0019 elecplot = 0;
0020 getfid = 0;
0021 coregister = 0;
0022
0023
0024
0025 create = 0;
0026
0027 correct = 0;
0028
0029
0030
0031
0032 emse = 0;
0033
0034 freesurfer = 1;
0035
0036
0037
0038
0039
0040
0041
0042 mriFID.sub{ 1} = 'c01';
0043 mriFID.xyz{ 1} = [ 0.005 0.097 -0.022; 0.071 0.023 -0.052; -0.072 0.016 -0.050 ];
0044 mriFID.sub{ 2} = 'c02';
0045 mriFID.xyz{ 2} = [ 0.007 0.088 -0.007; 0.081 0.015 -0.046; -0.070 0.012 -0.051 ];
0046 mriFID.sub{ 3} = 'c03';
0047 mriFID.xyz{ 3} = [ -0.002 0.098 -0.008; 0.055 0.040 -0.038; -0.095 0.030 -0.046 ];
0048 mriFID.sub{ 4} = 'c04';
0049 mriFID.xyz{ 4} = [ 0.000 0.092 0.000; 0.070 0.024 -0.036; -0.076 0.031 -0.036 ];
0050 mriFID.sub{ 5} = 'c05';
0051 mriFID.xyz{ 5} = [ 0.010 0.094 -0.010; 0.075 0.024 -0.048; -0.072 0.024 -0.052 ];
0052 mriFID.sub{ 6} = 'c06';
0053 mriFID.xyz{ 6} = [ -0.002 0.088 0.000; 0.077 0.008 -0.048; -0.075 -0.008 -0.048 ];
0054 mriFID.sub{ 7} = 'c07';
0055 mriFID.xyz{ 7} = [ -0.001 0.097 -0.018; 0.078 0.008 -0.055; -0.076 0.008 -0.055 ];
0056 mriFID.sub{ 8} = 'c08';
0057 mriFID.xyz{ 8} = [ 0.000 0.096 -0.019; 0.087 0.005 -0.039; -0.065 0.004 -0.038 ];
0058 mriFID.sub{ 9} = 'c09';
0059 mriFID.xyz{ 9} = [ 0.010 0.086 -0.020; 0.100 -0.020 -0.080; -0.060 0.020 -0.058 ];
0060 mriFID.sub{10} = 'c10';
0061 mriFID.xyz{10} = [ 0.000 0.091 -0.018; 0.076 0.011 -0.052; -0.068 0.006 -0.052 ];
0062
0063 mriFID.sub{11} = 'p02';
0064 mriFID.xyz{11} = [ 0.002 0.091 0.016; 0.080 0.025 -0.036; -0.080 0.015 -0.043 ];
0065 mriFID.sub{12} = 'p04';
0066 mriFID.xyz{12} = [ -0.001 0.086 -0.009; 0.086 0.002 -0.062; -0.070 0.003 -0.065 ];
0067 mriFID.sub{13} = 'p05';
0068 mriFID.xyz{13} = [ -0.002 0.094 -0.001; 0.068 0.025 -0.040; -0.071 0.005 -0.042 ];
0069 mriFID.sub{14} = 'p06';
0070 mriFID.xyz{14} = [ -0.002 0.084 0.000; 0.082 0.013 -0.050; -0.066 0.013 -0.052 ];
0071 mriFID.sub{15} = 'p07';
0072 mriFID.xyz{15} = [ 0.001 0.092 0.015; 0.080 0.003 -0.033; -0.070 0.004 -0.032 ];
0073 mriFID.sub{16} = 'p08';
0074 mriFID.xyz{16} = [ -0.003 0.095 -0.002; 0.070 0.018 -0.040; -0.074 0.022 -0.035 ];
0075 mriFID.sub{17} = 'p09';
0076 mriFID.xyz{17} = [ -0.002 0.100 0.004; 0.100 0.002 -0.028; -0.050 0.000 -0.036 ];
0077
0078
0079
0080
0081
0082 if meshplot & ~correct,
0083
0084 patch('vertices',p.mesh.data.vertices{4},'faces',p.mesh.data.faces{4},...
0085 'FaceColor',[1 0 0],'Edgecolor','none','FaceAlpha',.3);
0086
0087 daspect([1 1 1]); axis tight; hold on
0088
0089 patch('vertices',p.mesh.data.vertices{3},'faces',p.mesh.data.faces{3},...
0090 'FaceColor',[0 1 0],'Edgecolor','none','FaceAlpha',.5);
0091
0092 patch('vertices',p.mesh.data.vertices{2},'faces',p.mesh.data.faces{2},...
0093 'FaceColor',[0 0 1],'Edgecolor','none','FaceAlpha',1.0);
0094
0095 material dull
0096 camlight headlight
0097
0098 mouse_rotate
0099
0100 return
0101
0102
0103 v = 1;
0104
0105 vert = p.mesh.data.vertices{4};
0106 x = vert(v,1);
0107 y = vert(v,2);
0108 z = vert(v,3);
0109 plot3(x,y,z,'ro')
0110
0111 vert = p.mesh.data.vertices{3};
0112 x = vert(v,1);
0113 y = vert(v,2);
0114 z = vert(v,3);
0115 plot3(x,y,z,'go')
0116
0117 vert = p.mesh.data.vertices{2};
0118 x = vert(v,1);
0119 y = vert(v,2);
0120 z = vert(v,3);
0121 plot3(x,y,z,'bo')
0122
0123 clear vert v x y z
0124
0125 return
0126 end
0127
0128
0129 if elecplot,
0130
0131
0132 patch('vertices',p.mesh.data.vertices{4},'faces',p.mesh.data.faces{4},...
0133 'FaceColor',[1 0 0],'Edgecolor','none','FaceAlpha',.6);
0134
0135 lighting phong
0136 material dull
0137 camlight headlight
0138
0139 hold on
0140
0141 x = p.elec.data.x;
0142 y = p.elec.data.y;
0143 z = p.elec.data.z;
0144 plot3(x,y,z,'bo')
0145
0146
0147
0148
0149
0150
0151 daspect([1 1 1]); axis tight; hold on
0152
0153 mouse_rotate
0154
0155 return
0156
0157 end
0158
0159
0160
0161
0162 for sub = { S },
0163
0164
0165
0166
0167
0168
0169 IMG.path = sprintf('\\\\POTZII\\data\\freesurfer\\subjects\\ptsdpet-%s\\mri\\analyze\\',char(sub));
0170 IMG.scalp = sprintf('%s_orig_axial_ras',char(sub));
0171 IMG.oskull = sprintf('%s_orig_axial_ras_skull',char(sub));
0172 IMG.iskull = sprintf('%s_orig_axial_ras_bet',char(sub));
0173 IMG.intensity.scalp = 100;
0174 IMG.intensity.oskull = 0.05;
0175 IMG.intensity.iskull = 150;
0176 IMG.tolerance.scalp = 20;
0177 IMG.tolerance.oskull = 0.01;
0178 IMG.tolerance.iskull = 80;
0179
0180
0181
0182 FS.path = sprintf('\\\\POTZII\\data\\freesurfer\\subjects\\ptsdpet-%s\\surf\\',char(sub));
0183 FS.file = 'rh.pial.asc';
0184
0185
0186 if create,
0187 [p] = mesh_bem_shells(IMG,FS);
0188 p.mesh.path = FS.path;
0189 p.mesh.file = 'BS_subjecttess.mat';
0190 mesh_write(p);
0191 [p] = mesh_bem_correct(p);
0192 p.mesh.file = 'BS_corrected_subjecttess.mat';
0193 mesh_write(p);
0194
0195 clear p
0196 end
0197
0198
0199
0200
0201 [p] = mesh_open;
0202
0203
0204
0205 p.mesh.path = sprintf('\\\\POTZII\\data\\data_source\\%s\\meshes\\',char(sub));
0206 p.mesh.file = sprintf('%s_subjecttess.mat',char(sub));
0207 [p] = mesh_open(p);
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233 if correct,
0234 dist.four2three = 5;
0235 dist.four2two = 4;
0236 dist.three2two = 3;
0237 dist.two2one = 1;
0238 [p] = mesh_bem_correct(p,[],dist,[],0);
0239 end
0240
0241
0242
0243
0244
0245 if coregister,
0246
0247
0248
0249
0250 if getfid,
0251 cd(IMG.path)
0252 avw = avw_img_read(IMG.scalp);
0253 avw_view(avw);
0254 return
0255 end
0256
0257
0258 p.elec.path = sprintf('\\\\POTZII\\data\\data_source\\%s\\meshes\\',char(sub));
0259 p.elec.file = sprintf('%s_124fit.txt',char(sub));
0260 p.elec.plot = 0;
0261 [p] = elec_open(p);
0262
0263
0264 Nfid = strmatch(sub,mriFID.sub);
0265
0266 p.mri.fiducials = mriFID.xyz{Nfid};
0267
0268 Efid = [p.elec.data.nasion; p.elec.data.rpa; p.elec.data.lpa];
0269
0270 T = fiducial_coregister(Efid,p.mri.fiducials);
0271
0272 [path,file,ext] = fileparts([p.elec.path p.elec.file]);
0273 file = fullfile(path,[file,'_reg.mat']);
0274 save(file,'T')
0275
0276
0277 E = [p.elec.data.x p.elec.data.y p.elec.data.z];
0278 E2MRI = [E,ones(size(E,1),1)] * T;
0279
0280 p.elec.data.x = E2MRI(:,1);
0281 p.elec.data.y = E2MRI(:,2);
0282 p.elec.data.z = E2MRI(:,3);
0283
0284 REF2MRI = [p.elec.data.ref 1] * T;
0285 p.elec.data.ref = REF2MRI(:,1:3);
0286
0287 ORIGIN2MRI = [p.elec.data.centroid 1] * T;
0288 p.elec.data.centroid = ORIGIN2MRI(:,1:3);
0289
0290 Efid2MRI = [ Efid [ 1 1 1]' ] * T;
0291 p.elec.data.nasion = Efid2MRI(1,1:3);
0292 p.elec.data.rpa = Efid2MRI(2,1:3);
0293 p.elec.data.lpa = Efid2MRI(3,1:3);
0294
0295
0296 clear E REF2MRI ORIGIN2MRI Efid2MRI
0297
0298
0299
0300
0301 p.elec.file = sprintf('%s_124fit_new.elp',char(sub));
0302 elec_write_emse(p);
0303
0304 end
0305
0306
0307 if emse,
0308 p.mesh.file = sprintf('%s.wfr',char(sub));
0309 p.mesh.type = 'emse';
0310 mesh_write(p);
0311 end
0312
0313
0314 if freesurfer,
0315 p.mesh.path = FS.path;
0316 p.mesh.file = 'rh.asc';
0317 p.mesh.type = 'freesurfer';
0318 p.mesh.data.meshtype{1} = '';
0319 mesh_write(p);
0320 end
0321
0322 end
0323
0324 return