-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpm6_Spatial_processing_THK5351_flutemetamol.m
141 lines (127 loc) · 5.15 KB
/
pm6_Spatial_processing_THK5351_flutemetamol.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
function Spatial_processing_PET_THK5351_flutemetamol_Part_I(radiotracer)
%
% % Script Part I: spatial processing of PET data of two radiotracers
% (THK5351 and flutemetamol). The script contains : Loading data (PET raw
% data "Ecat format"), conversion of the data into .nii, rename of images,
% realignment of the dynamic data and creation of the sumframe image.
%
% Radiotracers: THK5351 = 1; Flutemetamol = 2;
% THK5351: 40 to 60 min corresponding to 23-26 frames
% Flutemetamol: all frames
%
% Note: data is supposed to be organized as follow:
% % /root_pth/subject-name/PET (PET data)
% % /root_pth/subject-name/MRI/nii (MRI files)
%
% M.Bahri: 2017/09/04
% -------------------------------------------------------------------------
% =========================================================================
global data;
spm pet;
root_pth ='D:\thk';
addpath('D:\thk\thk_codes')
data = pm0_COF_data(fullfile(root_pth));
Ren = {'1' '01';...
'2' '02';...
'3' '03';...
'4' '04';...
'5' '05';...
'6' '06';...
'7' '07';...
'8' '08';...
'9' '09';...
'10' '0a';...
'11' '0b';...
'12' '0c';...
'13' '0d';...
'14' '0e';...
'15' '0f';...
'16' '10';...
'17' '11';...
'18' '12';...
'19' '13';...
'20' '14';...
'21' '15';...
'22' '16';...
'23' '17';...
'24' '18';...
'25' '19';...
'26' '1a';...
'27' '1b';...
'28' '1c';...
'29' '1d';...
'30' '1e';...
'31' '1f';...
'32' '20';...
'33' '21';...
'34' '22';...
'35' '23';...
'36' '24';...
'37' '25';...
'38' '26';...
'39' '27'};
for isub = 1:size(data,2)
fprintf(1,'PROCESSING SUBJECT %i : %s\n',isub,data(isub).id)
% check for MRI an dPET directories
cd(fullfile(data(isub).dir));
if exist('MRI','dir')==0
fprintf(1,'Pas de MRI pour %s\n',data(isub).id)
elseif exist('PET','dir')==0
fprintf(1,'Pas de PET pour %s\n',data(isub).id)
else
% Dynamic PET: Loading ".v"
PET_dir = fullfile(data(isub).dir,'PET');
[rawPET] = spm_select('FPList',PET_dir,strcat('^',data(isub).id,'_.+de10\.v$'));
PETDyn_dir = fullfile(PET_dir,'Dynamic');
mkdir(PETDyn_dir);
cd(PETDyn_dir);
matlabbatch = [];
matlabbatch{1}.spm.util.import.ecat.data = cellstr(rawPET);
matlabbatch{1}.spm.util.import.ecat.opts.ext = 'nii';
spm_jobman('run',matlabbatch);
clear matlabbatch;
% Rename converted files : hexadecimal to decimal numbering
Nscan = size(ls('*.nii'),1);
[ncfiles]=spm_select('FPList',PETDyn_dir,strcat('^',data(isub).id,'*.+_de10_.+\.nii$'));
for i = size(ncfiles,1):-1:1
[pthref,namref,extref] = fileparts(ncfiles(i,:));
if(i < 10)
else
if strcmp(namref(end-1:end),Ren{i,2})==1
movefile(ncfiles(i,:),fullfile(pthref,[namref(1:end-2) Ren{i,1} extref]));
end
end
end
% Motion correction: realignment of frames without reslicing
[files]=spm_select('FPList',PETDyn_dir,strcat('^',data(isub).id,'*.+\.nii$'));
motion_correction_DynPET_noreslice(files);
% Create sumframe image (THK5351: 40-60 minutes coresponding to 23-26
% frames
[rnsfiles]=spm_select('FPList',PETDyn_dir,strcat('^rns',data(isub).id,'*.+\.nii$'));
[pth,nam,ext] = fileparts(rnsfiles(1,:));
cd(PET_dir);
% THK5351: 40-60 minutes coresponding to 23-26 frames
if(radiotracer == 1)
tpmfiles=[];
for i=23:26
tpmfiles = [tpmfiles;rnsfiles(i,:)];
end
matlabbatch{1}.spm.util.imcalc.input = cellstr(tpmfiles);
matlabbatch{1}.spm.util.imcalc.output = fullfile(PET_dir,[nam '_40-60' ext]);
matlabbatch{1}.spm.util.imcalc.expression = 'sum(X)';
matlabbatch{1}.spm.util.imcalc.options.dmtx = 1;
spm_jobman('run',matlabbatch);
clear matlabbatch;
end
% Flutemetamol: sum of all frames
if(radiotracer == 2)
matlabbatch{1}.spm.util.imcalc.input = cellstr(rnsfiles);
matlabbatch{1}.spm.util.imcalc.output = fullfile(PET_dir,[nam '_sumframes' ext]);
matlabbatch{1}.spm.util.imcalc.expression = 'sum(X)';
matlabbatch{1}.spm.util.imcalc.options.dmtx = 1;
spm_jobman('run',matlabbatch);
clear matlabbatch;
end
end
end
fprintf(1,'Attention: since the PET image will be coregistered to structural image,\n. It is necessary to reorient the PET *_sumframes.nii or/and PET *_40-60.nii\n into the T1/MT structural MRI image before running PART II\n')