-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathet_writefascicledensity.m
46 lines (39 loc) · 1.42 KB
/
et_writefascicledensity.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
function et_writefascicledensity(feFileToLoad, fname, b0file)
% Load fe file and the export the file including fascicle density per
% voxel.
% Reference:
% Takemura, H., Caiafa, C., Wandell, B.A. & Pestilli, F. (in revision) Ensemble
% Tractography.
%
% INPUT:
% feFileToLoad: A full path to .mat file including fe structure
% fname: The name of output file (.nii.gz format)
% b0file: A full path to nifti files storing MRI data in the identical size
% and resolution of diffusion data. Typically preprocessed B0 image.
%
% Example:
% feFileToLoad = 'S1_STN96_LH_Frontal_SPC_1_fe.mat';
% fname = 'S1_STN96_LH_Frontal_SPC_1_fiberdensity.nii.gz';
% b0file = '/EnsembleTractography_opendata/data/STN96/S1/S1_STN96_data/diffusion_raw/b0_run01.nii.gz';
%
% (C) Hiromasa Takemura, Stanford VISTA Lab
%
% Load fe structure
load(feFileToLoad);
% Compute fascicle density of optimized conneceome by retaining non-zero
% weight fascicles
fg = feGet(fe,'fibers acpc');
fweight = feGet(fe,'fiber weights');
fweight(fweight > 0) = 1;
fgkeep = fgExtract(fg, transpose(logical(fweight)), 'keep');
% Load b0 image
im = niftiRead(b0file);
% Create an image of fiber density where each voxel counts the number of
% fiber endpoints
fd = dtiComputeFiberDensityNoGUI(fgkeep,im.qto_xyz,size(im.data),0,1,0);
% Now build a nifti image that is coregistered to the B0 image
fdImg = im;
fdImg.data = fd;
fdImg.fname = fname;
% Write the nifti image
niftiWrite(fdImg);