forked from tkkarjal/magia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
magia_logan_image.m
53 lines (40 loc) · 1.6 KB
/
magia_logan_image.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
function parametric_images = magia_logan_image(pet_filename,input,frames,brainmask_filename,start_time,end_time,outputdir)
V = spm_vol(pet_filename);
pet_img = spm_read_vols(V);
pet_img = reshape(pet_img,[prod(V(1).dim(1:3)) size(V,1)])';
V = spm_vol(brainmask_filename);
mask = spm_read_vols(V) > 0;
non_nan_mask = reshape(~any(isnan(pet_img)),V.dim);
non_zero_mask = reshape(~any(pet_img <= 0),V.dim);
mask = mask & non_nan_mask & non_zero_mask;
pet_img = pet_img(:,mask);
fprintf('Starting Logan fit to %.0f voxels...',sum(mask(:)));
[Vt,intercept] = magia_fit_logan(pet_img,input,frames,start_time,end_time);
fprintf(' Ready.\n');
Vt_img = zeros(size(mask));
intercept_img = Vt_img;
Vt_img(mask) = Vt;
intercept_img(mask) = intercept;
parametric_images = cell(2,1);
[~,filename] = fileparts(pet_filename);
V.dt = [spm_type('int16') 0];
V.pinfo = [inf inf inf]';
if(end_time > 0)
niftiname = fullfile(outputdir,[filename '_Logan_Vt_' int2str(start_time) '_' int2str(end_time) '.nii']);
else
niftiname = fullfile(outputdir,[filename '_Logan_Vt_' int2str(start_time) '.nii']);
end
V.fname = niftiname;
V.private.dat.fname = niftiname;
spm_write_vol(V,Vt_img);
parametric_images{1} = niftiname;
if(end_time > 0)
niftiname = fullfile(outputdir,[filename '_Logan_intercept' int2str(start_time) '_' int2str(end_time) '.nii']);
else
niftiname = fullfile(outputdir,[filename '_Logan_intercept' int2str(start_time) '.nii']);
end
V.fname = niftiname;
V.private.dat.fname = niftiname;
spm_write_vol(V,intercept_img);
parametric_images{2} = niftiname;
end