1 | function calc_asl_cbf(DATA,ROI,AddInfo) |
---|
2 | % CALC_ASL_CBF - Calculate CBF maps from ASL data using T1-map data if |
---|
3 | % possible (Aedes plugin) |
---|
4 | % |
---|
5 | % |
---|
6 | % Synopsis: |
---|
7 | % |
---|
8 | % Description: |
---|
9 | % |
---|
10 | % Examples: |
---|
11 | % |
---|
12 | % See also: |
---|
13 | % |
---|
14 | |
---|
15 | % This function is a part of Aedes - A graphical tool for analyzing |
---|
16 | % medical images |
---|
17 | % |
---|
18 | % Copyright (C) 2006 Juha-Pekka Niskanen <Juha-Pekka.Niskanen@uku.fi> |
---|
19 | % |
---|
20 | % Department of Physics, Department of Neurobiology |
---|
21 | % University of Kuopio, FINLAND |
---|
22 | % |
---|
23 | % This program may be used under the terms of the GNU General Public |
---|
24 | % License version 2.0 as published by the Free Software Foundation |
---|
25 | % and appearing in the file LICENSE.TXT included in the packaging of |
---|
26 | % this program. |
---|
27 | % |
---|
28 | % This program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
---|
29 | % WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
---|
30 | |
---|
31 | % Defaults |
---|
32 | lambda = 0.9; |
---|
33 | t1map = 1.2; |
---|
34 | |
---|
35 | if AddInfo.isDataMixed |
---|
36 | % Check that the number of images is OK |
---|
37 | if rem(length(DATA),2)~=0 || length(DATA)==1 |
---|
38 | h=errordlg('The number of input images has to be divisible by 2!',... |
---|
39 | 'Error','modal'); |
---|
40 | return |
---|
41 | end |
---|
42 | controlIm = zeros([size(DATA{1}.FTDATA) length(DATA)/2]); |
---|
43 | labelIm = zeros([size(DATA{1}.FTDATA) length(DATA)/2]); |
---|
44 | for ii=1:2:size(controlIm,3) |
---|
45 | controlIm(:,:,ii) = DATA{ii}.FTDATA; |
---|
46 | labelIm(:,:,ii) = DATA{ii+1}.FTDATA; |
---|
47 | end |
---|
48 | for ii=1:length(DATA) |
---|
49 | ParentFileName{ii} = fullfile(DATA{ii}.HDR.fpath,DATA{ii}.HDR.fname); |
---|
50 | end |
---|
51 | else |
---|
52 | % Check that the number of images is OK |
---|
53 | if rem(size(DATA{1}.FTDATA,3),2)~=0 || size(DATA{1}.FTDATA,3)==1 |
---|
54 | h=errordlg('The number of input images has to be divisible by 2!',... |
---|
55 | 'Error','modal'); |
---|
56 | return |
---|
57 | end |
---|
58 | controlIm = DATA{1}.FTDATA(:,:,1:2:size(DATA{1}.FTDATA,3)); |
---|
59 | labelIm = DATA{1}.FTDATA(:,:,2:2:size(DATA{1}.FTDATA,3)); |
---|
60 | ParentFileName = fullfile(DATA{1}.HDR.fpath,DATA{1}.HDR.fname); |
---|
61 | end |
---|
62 | |
---|
63 | % Ask for lambda |
---|
64 | resp = an2_inputdlg('Lambda coefficient?','Lambda coefficient?',... |
---|
65 | num2str(lambda)); |
---|
66 | if isempty(resp) |
---|
67 | % Canceled |
---|
68 | return |
---|
69 | end |
---|
70 | lambda = str2num(resp{1}); |
---|
71 | |
---|
72 | % Ask for T1-map |
---|
73 | default_path = DATA{1}.HDR.fpath; |
---|
74 | if isempty(default_path) |
---|
75 | default_path = [pwd,filesep]; |
---|
76 | end |
---|
77 | |
---|
78 | resp = questdlg(['Select if you want to use a constant value for T1 ',... |
---|
79 | 'or an existing T1-map.'],... |
---|
80 | 'Use constant T1 value or T1-map?',... |
---|
81 | 'Use T1-map','Use constant T1','Cancel',... |
---|
82 | 'Use T1-map'); |
---|
83 | if isempty(resp) || strcmpi(resp,'Cancel') |
---|
84 | % Canceled |
---|
85 | return |
---|
86 | elseif strcmpi(resp,'Use constant T1') |
---|
87 | % Ask for T1 value |
---|
88 | resp = an2_inputdlg('Input T1 value','Input T1 value',... |
---|
89 | num2str(t1map)); |
---|
90 | if isempty(resp) |
---|
91 | % Canceled |
---|
92 | return |
---|
93 | end |
---|
94 | fname = ''; |
---|
95 | fpath = ''; |
---|
96 | t1map = str2num(resp{1}); |
---|
97 | t1val = t1map; |
---|
98 | else |
---|
99 | [fname,fpath,findex] = uigetfile({'*.t1','T1-Files (*.t1)';... |
---|
100 | '*.*','All Files (*.*)'},'Select T1-map to open',... |
---|
101 | default_path); |
---|
102 | if isequal(fname,0) |
---|
103 | % Canceled |
---|
104 | return |
---|
105 | end |
---|
106 | try |
---|
107 | tmp=load(fullfile(fpath,fname),'-mat'); |
---|
108 | t1map = tmp.Data; |
---|
109 | catch |
---|
110 | h=errordlg({'Could not open T1-map from file',... |
---|
111 | fullfile(fpath,fname)},'Error','modal'); |
---|
112 | return |
---|
113 | end |
---|
114 | |
---|
115 | |
---|
116 | % Check that the T1-map size matches with ASL. If it doesn't, resize it to |
---|
117 | % match... |
---|
118 | t1map = t1map(:,:,1); |
---|
119 | if ~isequal(size(t1map),[size(controlIm,1),size(controlIm,2)]) |
---|
120 | t1map = imresize(t1map,[size(controlIm,1),size(controlIm,2)]); |
---|
121 | end |
---|
122 | t1val = []; |
---|
123 | end |
---|
124 | |
---|
125 | % Convert milliseconds to seconds |
---|
126 | t1map=t1map./1000; |
---|
127 | |
---|
128 | % Calculate difference fotr ASL |
---|
129 | mean_control = mean(controlIm,3); |
---|
130 | mean_label = mean(labelIm,3); |
---|
131 | asl_map = mean_label-mean_control; |
---|
132 | |
---|
133 | % Calculate CBF and save it into a MAT-file |
---|
134 | cbf_map = (100.*60.*lambda.*asl_map)./(t1map.*2.*mean_control); |
---|
135 | cbf_map(isinf(cbf_map))=0; |
---|
136 | cbf_map(isnan(cbf_map))=0; |
---|
137 | |
---|
138 | % Ask where to save the resulting CBF map |
---|
139 | [fn,fp,fi] = uiputfile({'*.mat','Matlab MAT-Files (*.mat)';... |
---|
140 | '*.*','All Files (*.*)'},'Save CBF-map as...',... |
---|
141 | [default_path,'asl_cbf_map.mat']); |
---|
142 | if isequal(fname,0) |
---|
143 | % Canceled |
---|
144 | return |
---|
145 | end |
---|
146 | |
---|
147 | % Construct the map structure |
---|
148 | Data = cbf_map; |
---|
149 | Param.ParentFileName = ParentFileName; |
---|
150 | Param.T1FileName = fullfile(fpath,fname); |
---|
151 | Param.T1value = t1val; |
---|
152 | Param.Lambda = lambda; |
---|
153 | |
---|
154 | % Save the map |
---|
155 | try |
---|
156 | save(fullfile(fp,fn),'Data','Param','-mat'); |
---|
157 | catch |
---|
158 | h=errordlg({'Could not save CBF-map to',... |
---|
159 | fullfile(fp,fn)},'Error','modal'); |
---|
160 | return |
---|
161 | end |
---|
162 | |
---|
163 | |
---|
164 | |
---|
165 | |
---|
166 | |
---|
167 | |
---|
168 | |
---|
169 | |
---|
170 | |
---|