-
Notifications
You must be signed in to change notification settings - Fork 0
/
tc_mri2mesh.m
64 lines (56 loc) · 1.92 KB
/
tc_mri2mesh.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function [meshMR,MRsegments]=tc_mri2mesh(segments,varargin)
%% [meshMR,MRsegments] = tc_mri2mesh(segments,varargin)
% uses fieldtrip's ft_volumesegment and ft_prepare_mesh
%
% possible optinal input arguments as MATLAB name-value pairs:
%
% 'coordsys' MRI coordinate system as used by fieldtrip (default 'xyz')
% 'scalpsmooth' smoothing for scalp tissue (default 5)
% 'meshmethod' method used by fieldtrip to create the mesh (default 'projectmesh')
% 'numvertices' number of vertices for the output mesh (default 24000)
[FileName,PathName]=uigetfile('.nii');
if PathName~=0
% define defaults
MRI_coordsys='xyz';
MRI_scalpsmooth=5;
MRI_meshmethod='projectmesh';
MRI_numvertices=24000;
% if size(varargin,2)>1
% for n=1:2:size(varargin,2)
% switch varargin{n}
% case 'coordsys'
% MRI_coordsys=varargin{n+1};
% case 'scalpsmooth'
% MRI_scalpsmooth=varargin{n+1};
% case 'meshmethod'
% MRI_meshmethod=varargin{n+1};
% case 'numvertices'
% MRI_numvertices=varargin{n+1};
% end
% end
% end
disp('reading file...')
MRI=ft_read_mri([PathName,FileName]);
disp('done.')
MRI.coordsys=MRI_coordsys;
cfg = [];
cfg.output = segments;
cfg.scalpsmooth = MRI_scalpsmooth;
%cfg.scalpthreshold = 0.085;
disp('start segmentation...')
segment_tpm = ft_volumesegment(cfg,MRI);
disp('done.')
cfg = [];
cfg.method = MRI_meshmethod;
cfg.tissue = segments;
cfg.numvertices = MRI_numvertices;
disp('start mesh transformation...')
bnd = ft_prepare_mesh(cfg, segment_tpm);
disp('done.')
Mesh_MRI=bnd;
Mesh_MRI.VCoord=bnd.pos;
Mesh_MRI.FCoord(:,[1,3,5])=bnd.tri;
meshMR=Mesh_MRI;
MRsegments=segment_tpm;
end
end