source: plugins/fmri_plugins/correlation_mapping.m

Last change on this file 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: 10.4 KB
Line 
1function correlation_mapping(DATA,ROI,AddInfo)
2%
3% An Aedes plugin that calculates resting state funtional connectivity from
4% seed ROIs.
5
6
7% Only accept 3D or 4D data
8if AddInfo.isDataMixed || ndims(DATA{1}.FTDATA)==2
9  errordlg('Only 3D or 4D can be used with this plugin.','Error',...
10    'modal');
11  return
12end
13
14% If no ROIs are defined there is nothing to do here...
15if isempty(ROI)
16  errordlg('No ROIs defined.','Error',...
17    'modal');
18  return
19end
20
21% Prompt for filter parameters
22[cancelled,lowpass,hipass,detrending,...
23  reserve_mean,smoothing,global_normalization,TR]=l_FilterPrompt;
24if cancelled
25  return
26end
27data=DATA{1}.FTDATA;
28
29% Get the ROIs from current slice/volume
30if ndims(data)==3
31  % Data volume upon which to show the maps
32  vol = data(:,:,1);
33  for ii=1:length(ROI)
34    ROI(ii).voxels{1} = ROI(ii).voxels{1}(:,:,AddInfo.CurrentSlice(3));
35  end
36else
37  vol = data(:,:,:,1);
38  for ii=1:length(ROI)
39    ROI(ii).voxels{1} = ROI(ii).voxels{1}(:,:,:,AddInfo.CurrentVol);
40  end
41end
42
43% Do global normalization
44if global_normalization
45  data = fmri_global_norm(data);
46end
47
48% Spatially smooth data
49if ~isempty(smoothing)
50  data = fmri_smooth(data,smoothing);
51end
52
53% Do fMRI filtering
54if ~isempty(lowpass) || ~isempty(hipass) || detrending
55  if detrending
56    val_trend = 'on';
57  else
58    val_trend = 'off';
59  end
60  if reserve_mean
61    val_mean = 'on';
62  else
63    val_mean = 'off';
64  end
65  data = fmri_filter(data,TR,'detrending',val_trend,...
66    'lowpass',lowpass,'hipass',hipass,...
67    'reservemean',val_mean);
68end
69
70% Correlate seeds
71corrmap = fmri_corr(data,ROI);
72
73% Display results in a new Aedes window
74dt = repmat(vol,[1 1 1 length(corrmap)]);
75rs_maps = zeros(size(corrmap(1).ccc,1),size(corrmap(1).ccc,2),...
76  size(corrmap(1).ccc,3),length(corrmap));
77for kk=1:length(corrmap)
78  rs_maps(:,:,:,kk) = corrmap(kk).ccc;
79end
80aedes(dt,[],rs_maps)
81
82
83
84%% --------------------------------------
85function [cancelled,lowpass,hipass,detrending,reserve_mean,smoothing,global_normalization,TR]=l_FilterPrompt()
86
87GD=aedes_gui_defaults;
88
89% Defaults
90if ~ispref('Aedes','CorrelationMapping')
91  hipass = [];
92  lowpass = 0.08;
93  detrending = true;
94  smoothpr = false;
95  reserve_mean = true;
96  global_normalization = true;
97  smoothing = [2 2 1];
98  TR = 2;
99else
100  tmp=getpref('Aedes','CorrelationMapping');
101  hipass=tmp.hipass;
102  lowpass=tmp.lowpass;
103  detrending=tmp.detrending;
104  reserve_mean=tmp.reserve_mean;
105  global_normalization=tmp.global_normalization;
106  smoothing=tmp.smoothing;
107  TR=tmp.TR;
108end
109if isempty(smoothing)
110  do_smoothing = false;
111else
112  do_smoothing = true;
113end
114cancelled = false;
115
116fig_h = 410;
117fig_w = 300;
118scrsz = get(0,'screensize');
119fh = figure('position',[(scrsz(3)-fig_w)/2 ...
120  (scrsz(4)-fig_h)/2 fig_w fig_h],...
121  'menubar','none',...
122  'Name','Correlation mapping options',...
123  'Numbertitle','off',...
124  'closereq','uiresume(gcbf)',...
125  'Color',GD.col.mainfig);
126
127% Low pass filter options
128lp_uipanel_height = 80;
129lph = uipanel('parent',fh,...
130  'units','pixel',...
131  'position',[5 fig_h-lp_uipanel_height ...
132  fig_w-10 lp_uipanel_height],...
133  'Title','Low-pass options',...
134  'backgroundcolor',GD.col.frame);
135
136tmp = get(lph,'position');
137use_lowpass_h = uicontrol('parent',lph,...
138  'units','pixel',...
139  'position',[5 tmp(4)-40 tmp(3)-50 20],...
140  'string','Low-pass filter data',...
141  'style','checkbox',...
142  'value',false,...
143  'callback',...
144  ['if get(gcbo,''value''),set(get(gcbo,''userdata''),''enable'',''on''),',...
145  'else,set(get(gcbo,''userdata''),''enable'',''off''),end'],...
146  'backgroundcolor',GD.col.frame);
147
148tmp = get(use_lowpass_h,'position');
149lp_cutoff_tx = uicontrol('parent',lph,...
150  'position',[25 tmp(2)-30 tmp(3)-50 20],...
151  'string','Low-pass filter cut-off:',...
152  'style','text',...
153  'horizontalalign','left',...
154  'enable','off',...
155  'backgroundcolor',GD.col.frame);
156
157tmp = get(lp_cutoff_tx,'position');
158lp_cutoff_h = uicontrol('parent',lph,...
159  'units','pixel',...
160  'position',[tmp(1)+tmp(3) tmp(2) 50 25],...
161  'style','edit',...
162  'string',num2str(lowpass),...
163  'enable','off',...
164  'backgroundcolor','w');
165
166set(use_lowpass_h,'userdata',[lp_cutoff_tx,lp_cutoff_h]);
167
168if ~isempty(lowpass)
169  set(lp_cutoff_h,'string',num2str(lowpass))
170  set(use_lowpass_h,'value',1)
171  set([lp_cutoff_tx,lp_cutoff_h],'enable','on')
172end
173
174% Hipass filter options
175hp_uipanel_height = 110;
176tmp = get(lph,'position');
177hph = uipanel('parent',fh,...
178  'units','pixel',...
179  'position',[5 fig_h-hp_uipanel_height-tmp(4)-5 ...
180  fig_w-10 hp_uipanel_height],...
181  'Title','High-pass options',...
182  'backgroundcolor',GD.col.frame);
183
184tmp = get(hph,'position');
185use_hipass_h = uicontrol('parent',hph,...
186  'units','pixel',...
187  'position',[5 tmp(4)-40 tmp(3)-50 20],...
188  'string','High-pass filter data',...
189  'style','checkbox',...
190  'value',false,...
191  'callback',...
192  ['if get(gcbo,''value''),',...
193  'if get(getappdata(gcbo,''detrend_checkbox''),''value''),',...
194  'set(getappdata(gcbo,''detrend_checkbox''),''enable'',''on'');',...
195  'else,set(get(gcbo,''userdata''),''enable'',''on'');end,',...
196  'else,set(get(gcbo,''userdata''),''enable'',''off'');end'],...
197  'backgroundcolor',GD.col.frame);
198
199tmp = get(use_hipass_h,'position');
200hp_cutoff_tx = uicontrol('parent',hph,...
201  'position',[25 tmp(2)-30 tmp(3)-50 20],...
202  'string','High-pass filter cut-off:',...
203  'style','text',...
204  'horizontalalign','left',...
205  'enable','off',...
206  'backgroundcolor',GD.col.frame);
207
208tmp = get(hp_cutoff_tx,'position');
209hp_cutoff_h = uicontrol('parent',hph,...
210  'units','pixel',...
211  'position',[tmp(1)+tmp(3) tmp(2) 50 25],...
212  'style','edit',...
213  'string',num2str(hipass),...
214  'enable','off',...
215  'backgroundcolor','w');
216
217hp_detrend_h = uicontrol('parent',hph,...
218  'units','pixel',...
219  'position',[25 tmp(2)-30 tmp(3) 25],...
220  'style','checkbox',...
221  'string','Remove only linear trend',...
222  'enable','off',...
223  'value',false,...
224  'callback',...
225  ['if get(gcbo,''value''),',...
226  'set(get(gcbo,''userdata''),''enable'',''off''),',...
227  'else,set(get(gcbo,''userdata''),''enable'',''on''),end'],...
228  'backgroundcolor',GD.col.frame);
229
230
231set(use_hipass_h,'userdata',[hp_cutoff_tx,hp_cutoff_h,hp_detrend_h]);
232set(hp_detrend_h,'userdata',[hp_cutoff_tx,hp_cutoff_h])
233setappdata(use_hipass_h,'detrend_checkbox',hp_detrend_h)
234
235if ~isempty(hipass)
236  set(use_hipass_h,'value',1)
237  set([hp_cutoff_tx,hp_cutoff_h,hp_detrend_h],'enable','on')
238end
239if detrending
240  set(hp_detrend_h,'value',1,'enable','on')
241  set([hp_cutoff_tx,hp_cutoff_h],'enable','off')
242  set(use_hipass_h,'value',1)
243end
244
245
246% Other options
247other_uipanel_height = 160;
248tmp = get(hph,'position');
249oph = uipanel('parent',fh,...
250  'units','pixel',...
251  'position',[tmp(1) tmp(2)-other_uipanel_height-5 ...
252  fig_w-10 other_uipanel_height],...
253  'Title','Other options',...
254  'backgroundcolor',GD.col.frame);
255
256tmp=get(oph,'position');
257tr_tx = uicontrol('parent',oph,...
258  'units','pixel',...
259  'position',[5 tmp(4)-40 tmp(3)-50-10 20],...
260  'string','Repetition time (TR):',...
261  'style','text',...
262  'horizontalalign','left',...
263  'enable','on',...
264  'backgroundcolor',GD.col.frame);
265
266tmp = get(tr_tx,'position');
267tr_h = uicontrol('parent',oph,...
268  'units','pixel',...
269  'position',[tmp(1)+tmp(3) tmp(2) 50 25],...
270  'style','edit',...
271  'string',num2str(TR),...
272  'enable','on',...
273  'backgroundcolor','w');
274
275
276resmean_h = uicontrol('parent',oph,...
277  'units','pixel',...
278  'position',[tmp(1) tmp(2)-25 tmp(3) 20],...
279  'style','checkbox',...
280  'string','Reserve mean',...
281  'enable','on',...
282  'value',reserve_mean,...
283  'backgroundcolor',GD.col.frame);
284
285tmp=get(resmean_h,'position');
286globalnorm_h = uicontrol('parent',oph,...
287  'units','pixel',...
288  'position',[tmp(1) tmp(2)-25 tmp(3) 20],...
289  'style','checkbox',...
290  'string','Global normalization',...
291  'enable','on',...
292  'value',global_normalization,...
293  'backgroundcolor',GD.col.frame);
294
295tmp=get(globalnorm_h,'position');
296smooting_h = uicontrol('parent',oph,...
297  'units','pixel',...
298  'position',[tmp(1) tmp(2)-25 tmp(3) 20],...
299  'style','checkbox',...
300  'string','Smooth data',...
301  'enable','on',...
302  'value',do_smoothing,...
303  'callback',...
304  ['if get(gcbo,''value''),set(get(gcbo,''userdata''),''enable'',''on''),',...
305  'else,set(get(gcbo,''userdata''),''enable'',''off''),end'],...
306  'backgroundcolor',GD.col.frame);
307
308tmp=get(smooting_h,'position');
309smooth_kernel_tx = uicontrol('parent',oph,...
310  'position',[25 tmp(2)-30 tmp(3)-60 20],...
311  'string','Smoothing kernel FWHM:',...
312  'style','text',...
313  'horizontalalign','left',...
314  'enable','off',...
315  'backgroundcolor',GD.col.frame);
316
317tmp = get(smooth_kernel_tx,'position');
318smooth_kernel_h = uicontrol('parent',oph,...
319  'units','pixel',...
320  'position',[tmp(1)+tmp(3) tmp(2) 60 25],...
321  'style','edit',...
322  'string',num2str(smoothing),...
323  'enable','off',...
324  'backgroundcolor','w');
325if do_smoothing
326  set([smooth_kernel_tx,smooth_kernel_h],'enable','on');
327end
328
329set(smooting_h,'userdata',[smooth_kernel_tx,smooth_kernel_h]);
330
331
332% Ok & Cancel buttons
333btn_w = 80;
334btn_h = 35;
335ok_btn_h = uicontrol('parent',fh,...
336  'units','pixel',...
337  'position',[fig_w-btn_w*2-10 5 btn_w btn_h],...
338  'style','pushbutton',...
339  'string','OK',...
340  'enable','on',...
341  'userdata',false,...
342  'callback','set(gcbo,''userdata'',true),uiresume(gcbf)');
343
344cancel_btn_h = uicontrol('parent',fh,...
345  'units','pixel',...
346  'position',[fig_w-btn_w-5 5 btn_w btn_h],...
347  'style','pushbutton',...
348  'string','Cancel',...
349  'enable','on',...
350  'callback','uiresume(gcbf)');
351
352% Wait for gui
353uiwait(fh);
354
355% Check if canceled
356if ~ishandle(fh) || ~get(ok_btn_h,'userdata')
357  % Cancelled
358  cancelled = true;
359  delete(fh)
360  return
361end
362
363% Get gui values
364if get(use_lowpass_h,'value')
365  lowpass = str2num(get(lp_cutoff_h,'string'));
366else
367  lowpass = [];
368end
369
370if get(use_hipass_h,'value')
371  if get(hp_detrend_h,'value')
372    hipass = [];
373    detrending = true;
374  else
375    hipass = str2num(get(hp_cutoff_h,'string'));
376    detrending = false;
377  end
378else
379  hipass = [];
380  detrending = false;
381end
382
383if get(resmean_h,'value')
384  reserve_mean = true;
385else
386  reserve_mean = false;
387end
388
389TR=str2num(get(tr_h,'string'));
390
391if get(globalnorm_h,'value')
392  global_normalization = true;
393else
394  global_normalization = false;
395end
396
397if get(smooting_h,'value')
398  smoothing = str2num(get(smooth_kernel_h,'string'));
399else
400  smoothing = [];
401end
402
403% Save prefs
404pref.hipass=hipass;
405pref.lowpass=lowpass;
406pref.detrending=detrending;
407pref.reserve_mean=reserve_mean;
408pref.global_normalization=global_normalization;
409pref.smoothing=smoothing;
410pref.TR=TR;
411setpref('Aedes','CorrelationMapping',pref);
412
413% Close figure window
414delete(fh)
415
Note: See TracBrowser for help on using the repository browser.

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