source: plugins/fmri_plugins/roi_averages.m

Last change on this file was 92, checked in by tjniskan, 10 years ago
  • Fixed a small bug in the roi averages plugin.

M plugins/fmri_plugins/roi_averages.m
M aedes_revision.m

File size: 2.6 KB
Line 
1function roi_averages(DATA,ROI,AddInfo)
2%
3% This Aedes plugin calculates and plots average time series from ROIs
4%
5
6if AddInfo.isDataMixed
7  % Make data a 4D-matrix if it is loaded in aedes as a stack of 2D or 3D images
8  DATA2{1}=DATA{1};
9  DATA2{1}.FTDATA = zeros([size(DATA{1}.FTDATA,1),...
10    size(DATA{1}.FTDATA,2),size(DATA{1}.FTDATA,3),length(DATA)],...
11    class(DATA{1}.FTDATA));
12  for ii=1:length(DATA)
13    DATA2{1}.FTDATA(:,:,:,ii)=DATA{ii}.FTDATA;
14  end
15  DATA=DATA2;
16  CurrentVol=AddInfo.CurrentSlice;
17else
18  CurrentVol=AddInfo.CurrentVol;
19end
20
21CurrentVol=AddInfo.CurrentVol;
22
23% Check that there are ROIs defined at all
24if isempty(ROI)
25  % No ROIs defined, nothing to calculate
26  errordlg('No ROIs defined. At least one ROI must be drawn to the data to allow average ROI time series calculation.',...
27    'ROIs not defined.','modal');
28  return
29end
30
31% Check that there are ROIs defined in this volume
32RoiInds = [];
33for ii=1:length(ROI)
34  if any(any(any(ROI(ii).voxels{1}(:,:,:,CurrentVol))))
35    RoiInds(end+1)=ii;
36  end
37end
38
39% Return if there were no ROIs in the current volume
40if isempty(RoiInds)
41  errordlg('No ROIs defined in the current volume. At least one ROI must be drawn to the current volume to allow average ROI time series calculation.',...
42    'ROIs not defined in current volume.','modal');
43  return
44end
45
46% Plot time series from ROIs
47nScans = size(DATA{1}.FTDATA,4);
48fh=figure;
49if length(RoiInds)<=3
50  nRows = length(RoiInds);
51  nCols=1;
52elseif length(RoiInds)==4
53  nRows = 2;
54  nCols=2;
55elseif length(RoiInds)<10
56  nRows = 3;
57  nCols = ceil(length(RoiInds)/nRows);
58else
59  nRows = 4;
60  nCols = ceil(length(RoiInds)/nRows);
61end
62for kk=RoiInds
63 
64  % Get time-series indices from ROI
65  ind = repmat(ROI(kk).voxels{1}(:,:,:,CurrentVol),[1 1 1 size(DATA{1}.FTDATA,4)]);
66 
67  % Mean EPI time series
68  ts_data = reshape(double(DATA{1}.FTDATA(ind)),[],size(DATA{1}.FTDATA,4));
69  ts_data = ts_data.';
70  ts_data = detrend(ts_data)+repmat(mean(ts_data),size(ts_data,1),1);
71 
72  % Normalize mean to bold-%
73  mean_ts_data = mean(ts_data,2);
74  mean_ts_data = (mean_ts_data./mean(mean_ts_data)-1)*100;
75 
76  data_trend=aedes_trendest(double(mean_ts_data),10);
77 
78  % Plot results
79  ax=subplot(nRows,nCols,kk,'align','parent',fh);
80  line(1:length(mean_ts_data),mean_ts_data,'color','k',...
81    'parent',ax);
82  line(1:length(mean_ts_data),data_trend,...
83    'color','r','linewidth',2,'parent',ax);
84  title(['Time series for ROI: ',ROI(kk).label])
85  ylabel(ax,'BOLD-%');
86  set(ax,'xlim',[0 length(mean_ts_data)],...
87    'ylim',[min(mean_ts_data)-min(mean_ts_data)*0.05 ...
88    max(mean_ts_data)+max(mean_ts_data)*0.05]);
89end
Note: See TracBrowser for help on using the repository browser.

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