-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredictDWInifti.m
More file actions
72 lines (63 loc) · 2.05 KB
/
predictDWInifti.m
File metadata and controls
72 lines (63 loc) · 2.05 KB
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
65
66
67
68
69
70
function pNifti = predictDWInifti(fe, dwi)
%
% pNifti = predictDWInifti(fe, dwi)
%
% This function gives you prediction diffusion nifti file based on LiFE
% weights
%
% INPUT
% fe ; After running feConnectomeInit and fitting a model
% dwi ; Structure made by dwiCreate
%
% Example
% fe;
% dwiFile = fullpath to 'dwi1st_b2000_150dirs.nii.gz';
% fgFileName = fullpath to 'fgFileName.mat or .pdb';
% feFileName = 'life_build_model_demo_CSD_PROB';
% dwiFileRepeat = fullpath to 'dwi2nd_b2000_150dirs.nii.gz';
% t1File = full path to 't1.nii.gz';
% % Run LiFE
% fe = feConnectomeInit(dwiFile,fgFileName,feFileName,[],dwiFileRepeat,t1File);
%
% % fit the model
% fe = feSet(fe,'fit',feFitModel(feGet(fe,'mfiber'),feGet(fe,'dsigdemeaned'),'bbnnls'));
%
% dwi;
% bvecs = dlmread('dwi1st_b2000_150dirs.bvecs');
% bvals = dlmread('dwi1st_b2000_150dirs.bvals');
% dwi = dwiCreate('nifti',dwiFile,'bvecs',bvecs','bvals',bvals');
%
% See; feConnectomeBuildModel, feGet ...
% SO wrote 2015
%% Here is the predicted signal from the life fit for the whole connectome
pSig = feGet(fe,'pSig full');
coords = feGet(fe,'roi coords');
nVoxels = feGet(fe,'nVoxels');
nBvecs = feGet(fe,'nbvecs');
nB0 = length(find(dwi.bvals==0));
% Take the pSig values and put them in a data volume like the nifti data
% volume
roiSig = zeros(size(dwi.nifti.data));
for cc=1:nVoxels
roiSig(coords(cc,1),coords(cc,2),coords(cc,3),(nB0+1):end) =...
pSig((cc-1)*nBvecs + (1:nBvecs));
end
%% Make an empty nifti file the same size as the original
% check
% if ~struct(dwi) && ischar(dwi);
% dwi = niftiRead(dwi);
% end
% Put pSig back to original nifti
pData = dwi.nifti.data;
for cc=1:nVoxels
pData(coords(cc,1),coords(cc,2),coords(cc,3),11:end) = pSig((cc-1)*nBvecs + (1:nBvecs));
end
%% duplicate original nifti structure
pNifti = dwi.nifti;
pNifti.data = pData;
% strip extension
[p,f] = fileparts(pNifti.fname);
[~,f] = fileparts(f);
% give correct extension to the file
newFname = fullfile(p,[f,'_Psig.nii.gz']);
pNifti.fname = newFname;