-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlife_preprocess.m
53 lines (37 loc) · 1.93 KB
/
life_preprocess.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
%% Example LiFE preprocessing.
% Dependencies.
https://github.com/vistalab/vistasoft
https://github.com/brain-life/encode
%% INPUTS.
t1File = fullfile(feDemoDataPath('STN','sub-FP','anatomy'), 't1.nii.gz');
fgFileName = fullfile(feDemoDataPath('STN','sub-FP','tractography'),'run01_fliprot_aligned_trilin_csd_lmax10_wm_SD_PROB-NUM01-500000.tck');
dwiFile = fullfile(feDemoDataPath('STN','sub-FP','dwi'),'run01_fliprot_aligned_trilin.nii.gz');
feFileName = 'LiFE_build_model_demo_STN_FP_CSD_PROB';
%% Encode the data and tractography into an FE structure.
% Discretization parameter (this parameter defines the resolution of the
% Phi tensor in describing the orientation of the fascicles in the
% connectome (number of orientations encoded in Phi, more specifically the
% size of Phi in mode 1).
L = 360;
% The function feConnectomeInit.m collects all the information necessary to
% encode a connectome and build a decomposed LiFE model (see Pestilli et
% al., 2015 and Caiafa & Pestilli Under Review).
%
% Here after we use the function to encode the model first. Below we
% extract the tensor encoding the connectome (Phi).
fe = feConnectomeInit(dwiFile,fgFileName,feFileName,[],dwiFile,t1File,L,[1,0]);
%% Fit the model.
% Hereafter we fit the forward model of tracrography using a least-squared
% method. The information generated by fitting the model (fiber weights
% etc) is then installed in the LiFE structure.
Niter = 500;
fe = feSet(fe,'fit',feFitModel(feGet(fe,'model'),feGet(fe,'dsigdemeaned'),'bbnnls',Niter,'preconditioner'));
%% Clear tractogrpahy using the LiFE model fit.
% Extract the weight assigned to eahc white matter fascicle
w = feGet(fe,'fiber weights');
% Extract the fascicles in AC-PC brain space.
fg = feGet(fe, 'fibers acpc');
% Use the weight to eliminate non-preferable fascicles (w = 0)
fg = fgExtract(fg, w > 0, 'keep');
% Write resulting optimized fg back to disk.
fgWrite(fg, 'path/to/file/filenam.mat');