source: plugins/calc_asl_cbf.m @ 161

Last change on this file since 161 was 129, checked in by tjniskan, 9 years ago
  • Added plugin for correlation mapping with filtering/other options
  • Added flipping of 3D ROIs in aedes.m
  • Added possibility of changing ROI color (in the ROI -uimenu)
  • Minor fixes/changes here and there...

M misclib/fmri_spm_volumes.m
M misclib/fmri_filter.m
M aedes_fitmaps.m
M aedes.m
M plugins/save_roi_as_mask.m
M plugins/calc_asl_cbf.m
A plugins/fmri_plugins/correlation_mapping.m
M plugins/fmri_plugins/resting_state_fc.m
M plugins/map_plugins/t1_inversion_recovery.m
M aedes_revision.m

File size: 4.5 KB
Line 
1function 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
32lambda = 0.9;
33t1map = 1.2;
34
35if 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
51else
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  if isfield(DATA{1}.PROCPAR,'ltype') && ...
59      length(DATA{1}.PROCPAR.ltype)==size(DATA{1}.FTDATA,3)
60    control_ind = find(strcmpi(DATA{1}.PROCPAR.ltype,'c'));
61    label_ind = find(strcmpi(DATA{1}.PROCPAR.ltype,'l'));
62    controlIm = DATA{1}.FTDATA(:,:,control_ind);
63    labelIm = DATA{1}.FTDATA(:,:,label_ind);
64    ParentFileName = fullfile(DATA{1}.HDR.fpath,DATA{1}.HDR.fname);
65  else
66    controlIm = DATA{1}.FTDATA(:,:,1:2:size(DATA{1}.FTDATA,3));
67    labelIm = DATA{1}.FTDATA(:,:,2:2:size(DATA{1}.FTDATA,3));
68    ParentFileName = fullfile(DATA{1}.HDR.fpath,DATA{1}.HDR.fname);
69  end
70end
71
72% Ask for lambda
73resp = aedes_inputdlg('Lambda coefficient?','Lambda coefficient?',...
74  num2str(lambda));
75if isempty(resp)
76  % Canceled
77  return
78end
79lambda = str2num(resp{1});
80
81% Ask for T1-map
82default_path = DATA{1}.HDR.fpath;
83if isempty(default_path)
84  default_path = [pwd,filesep];
85end
86
87resp = questdlg(['Select if you want to use a constant value for T1 ',...
88  'or an existing T1-map.'],...
89  'Use constant T1 value or T1-map?',...
90  'Use T1-map','Use constant T1','Cancel',...
91  'Use T1-map');
92if isempty(resp) || strcmpi(resp,'Cancel')
93  % Canceled
94  return
95elseif strcmpi(resp,'Use constant T1')
96  % Ask for T1 value
97  resp = aedes_inputdlg('Input T1 value','Input T1 value',...
98        num2str(t1map));
99  if isempty(resp)
100        % Canceled
101        return
102  end
103  fname = '';
104  fpath = '';
105  t1map = str2num(resp{1});
106  t1val = t1map;
107else
108  [fname,fpath,findex] = uigetfile({'*.t1','T1-Files (*.t1)';...
109        '*.*','All Files (*.*)'},'Select T1-map to open',...
110        default_path);
111  if isequal(fname,0)
112        % Canceled
113        return
114  end
115  try
116        tmp=load(fullfile(fpath,fname),'-mat');
117        t1map = tmp.Data;
118  catch
119        h=errordlg({'Could not open T1-map from file',...
120          fullfile(fpath,fname)},'Error','modal');
121        return
122  end
123 
124
125  % Check that the T1-map size matches with ASL. If it doesn't, resize it to
126  % match...
127  t1map = t1map(:,:,1);
128  if ~isequal(size(t1map),[size(controlIm,1),size(controlIm,2)])
129        t1map = imresize(t1map,[size(controlIm,1),size(controlIm,2)]);
130  end
131  t1val = [];
132end
133
134% Convert milliseconds to seconds
135%t1map=t1map./1000;
136
137% Calculate difference fotr ASL
138mean_control = mean(controlIm,3);
139mean_label = mean(labelIm,3);
140asl_map = mean_control-mean_label;
141
142% Calculate CBF and save it into a MAT-file
143cbf_map = (100.*60.*lambda.*asl_map)./(t1map.*2.*mean_control);
144cbf_map(isinf(cbf_map))=0;
145cbf_map(isnan(cbf_map))=0;
146
147% Ask where to save the resulting CBF map
148[fn,fp,fi] = uiputfile({'*.mat','Matlab MAT-Files (*.mat)';...
149  '*.*','All Files (*.*)'},'Save CBF-map as...',...
150  [default_path,'asl_cbf_map.mat']);
151if isequal(fname,0)
152  % Canceled
153  return
154end
155
156% Construct the map structure
157Data = cbf_map;
158Param.ParentFileName = ParentFileName;
159Param.T1FileName = fullfile(fpath,fname);
160Param.T1value = t1val;
161Param.Lambda = lambda;
162
163% Save the map
164try
165  save(fullfile(fp,fn),'Data','Param','-mat');
166catch
167  h=errordlg({'Could not save CBF-map to',...
168        fullfile(fp,fn)},'Error','modal');
169  return
170end
171
172
173
174
175
176
177
178
179
Note: See TracBrowser for help on using the repository browser.

Powered by Trac 1.0.9.Copyright © Juha-Pekka Niskanen 2008