0001 function varargout = alff_gui(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 gui_Singleton = 1;
0020 gui_State = struct('gui_Name', mfilename, ...
0021 'gui_Singleton', gui_Singleton, ...
0022 'gui_OpeningFcn', @alff_gui_OpeningFcn, ...
0023 'gui_OutputFcn', @alff_gui_OutputFcn, ...
0024 'gui_LayoutFcn', [] , ...
0025 'gui_Callback', []);
0026 if nargin && ischar(varargin{1})
0027 gui_State.gui_Callback = str2func(varargin{1});
0028 end
0029
0030 if nargout
0031 [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0032 else
0033 gui_mainfcn(gui_State, varargin{:});
0034 end
0035
0036
0037
0038
0039 function alff_gui_OpeningFcn(hObject, eventdata, handles, varargin)
0040
0041 InitControlProperties(hObject, handles);
0042
0043 InitFrames(hObject,handles);
0044
0045 [pathstr, name, ext, versn] = fileparts(mfilename('fullpath'));
0046
0047 handles.Cfg.DataDirs ={};
0048 handles.Cfg.MaskFile = 'Default';
0049 handles.Cfg.OutputDir =pwd;
0050 handles.Cfg.WantMeanAlffMap ='Yes';
0051 handles.Filter.BandLow =0.01;
0052 handles.Filter.BandHigh =0.08;
0053 handles.Filter.UseFilter ='No';
0054 handles.Filter.Retrend ='Yes';
0055 handles.Filter.SamplePeriod=2;
0056 handles.Detrend.BeforeFilter ='No';
0057 handles.Detrend.AfterFilter ='No';
0058 handles.ALFF.BandLow =0.01;
0059 handles.ALFF.BandHigh =0.08;
0060 handles.ALFF.SamplePeriod =2;
0061 handles.Log.SelfPath =pathstr;
0062 handles.Log.Filename =GetLogFilename('','');
0063
0064 handles.Performance =0;
0065
0066 guidata(hObject, handles);
0067 UpdateDisplay(handles);
0068 movegui(handles.figAlffMain, 'center');
0069 set(handles.figAlffMain,'Name','Amplitude of Low Frequency Fluctuation');
0070
0071
0072 handles.output = hObject;
0073 guidata(hObject, handles);
0074
0075
0076
0077
0078
0079 function varargout = alff_gui_OutputFcn(hObject, eventdata, handles)
0080
0081 varargout{1} = handles.output;
0082
0083
0084
0085
0086 function edtDataDirectory_Callback(hObject, eventdata, handles)
0087 theDir =get(hObject, 'String');
0088 SetDataDir(hObject, theDir,handles);
0089
0090 function edtDataDirectory_CreateFcn(hObject, eventdata, handles)
0091 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0092 set(hObject,'BackgroundColor','white');
0093 end
0094
0095
0096 function btnSelectDataDir_Callback(hObject, eventdata, handles)
0097 if size(handles.Cfg.DataDirs, 1)>0
0098 theDir =handles.Cfg.DataDirs{1,1};
0099 else
0100 theDir =pwd;
0101 end
0102 theDir =uigetdir(theDir, 'Please select the data directory to compute alff map: ');
0103 if ischar(theDir),
0104 SetDataDir(hObject, theDir,handles);
0105 end
0106
0107 function RecursiveAddDataDir(hObject, eventdata, handles)
0108 if prod(size(handles.Cfg.DataDirs))>0 && size(handles.Cfg.DataDirs, 1)>0,
0109 theDir =handles.Cfg.DataDirs{1,1};
0110 else
0111 theDir =pwd;
0112 end
0113 theDir =uigetdir(theDir, 'Please select the parent data directory of many sub-folders containing EPI data to compute ALFF map: ');
0114 if ischar(theDir),
0115 setappdata(0, 'ALFF_DoingRecursiveDir', 1);
0116 theOldColor =get(handles.listDataDirs, 'BackgroundColor');
0117 set(handles.listDataDirs, 'BackgroundColor', [ 0.7373 0.9804 0.4784]);
0118 try
0119 rest_RecursiveDir(theDir, 'alff_gui(''SetDataDir'',gcbo, ''%s'', guidata(gcbo) )');
0120 catch
0121 rest_misc( 'DisplayLastException');
0122 end
0123 set(handles.listDataDirs, 'BackgroundColor', theOldColor);
0124 rmappdata(0, 'ALFF_DoingRecursiveDir');
0125 end
0126
0127 function SetDataDir(hObject, ADir, handles)
0128 if ~ischar(ADir), return; end
0129 theOldWarnings =warning('off', 'all');
0130
0131 if rest_misc('GetMatlabVersion')>=7.3,
0132 ADir =strtrim(ADir);
0133 end
0134 if (~isequal(ADir , 0)) &&( (size(handles.Cfg.DataDirs, 1)==0)||(0==length(strmatch(ADir,handles.Cfg.DataDirs( : , 1),'exact' ) ) ))
0135 handles.Cfg.DataDirs =[ {ADir , 0}; handles.Cfg.DataDirs];
0136 theVolumnCount =CheckDataDir(handles.Cfg.DataDirs{1,1} );
0137 if (theVolumnCount<=0),
0138 if isappdata(0, 'ALFF_DoingRecursiveDir') && getappdata(0, 'ALFF_DoingRecursiveDir'),
0139 else
0140 fprintf('There is no data or non-data files in this directory:\n%s\nPlease re-select\n\n', ADir);
0141 errordlg( sprintf('There is no data or non-data files in this directory:\n\n%s\n\nPlease re-select', handles.Cfg.DataDirs{1,1} ));
0142 end
0143 handles.Cfg.DataDirs(1,:)=[];
0144 if size(handles.Cfg.DataDirs, 1)==0
0145 handles.Cfg.DataDirs=[];
0146 end
0147 else
0148 handles.Cfg.DataDirs{1,2} =theVolumnCount;
0149 end
0150
0151 guidata(hObject, handles);
0152 UpdateDisplay(handles);
0153 end
0154 warning(theOldWarnings);
0155
0156
0157 function UpdateDisplay(handles)
0158 if size(handles.Cfg.DataDirs,1)>0
0159 theOldIndex =get(handles.listDataDirs, 'Value');
0160
0161 set(handles.listDataDirs, 'String', GetInputDirDisplayList(handles) , 'Value', 1);
0162 theCount =size(handles.Cfg.DataDirs,1);
0163 if (theOldIndex>0) && (theOldIndex<= theCount)
0164 set(handles.listDataDirs, 'Value', theOldIndex);
0165 end
0166 set(handles.edtDataDirectory,'String', handles.Cfg.DataDirs{1,1});
0167 theResultFilename=get(handles.edtPrefix, 'String');
0168 theResultFilename=[theResultFilename '_' GetDirName(handles.Cfg.DataDirs{1,1})];
0169 set(handles.txtResultFilename, 'String', [theResultFilename '.{hdr/img}']);
0170 else
0171 set(handles.listDataDirs, 'String', '' , 'Value', 0);
0172 set(handles.txtResultFilename, 'String', 'Result: Prefix_DirectoryName.{hdr/img}');
0173 end
0174
0175
0176
0177
0178 set(handles.edtOutputDir ,'String', handles.Cfg.OutputDir);
0179 if isequal(handles.Cfg.MaskFile, '')
0180 set(handles.edtMaskfile, 'String', 'Don''t use any Mask');
0181 else
0182 set(handles.edtMaskfile, 'String', handles.Cfg.MaskFile);
0183 end
0184
0185 if strcmpi(handles.Detrend.BeforeFilter, 'Yes')
0186
0187 set(handles.btnDetrend, 'Enable', 'on');
0188 else
0189
0190 set(handles.btnDetrend, 'Enable', 'off');
0191 end
0192
0193 if strcmpi(handles.Filter.UseFilter, 'Yes')
0194 set(handles.ckboxFilter, 'Value', 1);
0195 set(handles.ckboxRetrend, 'Enable', 'on');
0196 set(handles.edtBandLow, 'Enable', 'on', 'String', num2str(handles.Filter.BandLow));
0197 set(handles.edtBandHigh, 'Enable', 'on', 'String', num2str(handles.Filter.BandHigh));
0198 set(handles.edtSamplePeriod, 'Enable', 'on', 'String', num2str(handles.Filter.SamplePeriod));
0199
0200 set(handles.btnBandPass, 'Enable', 'on');
0201 else
0202 set(handles.ckboxFilter, 'Value', 0);
0203 set(handles.ckboxRetrend,'Enable', 'off');
0204 set(handles.edtBandLow, 'Enable', 'off', 'String', num2str(handles.Filter.BandLow));
0205 set(handles.edtBandHigh, 'Enable', 'off', 'String', num2str(handles.Filter.BandHigh));
0206 set(handles.edtSamplePeriod, 'Enable', 'off', 'String', num2str(handles.Filter.SamplePeriod));
0207
0208 set(handles.btnBandPass, 'Enable', 'off');
0209 end
0210
0211
0212 set(handles.ckboxDivideMean, 'Value', strcmpi(handles.Cfg.WantMeanAlffMap, 'Yes'));
0213
0214
0215 set(handles.ckboxRemoveTrendBefore, 'Value', strcmpi(handles.Detrend.BeforeFilter, 'Yes'));
0216 set(handles.ckboxRemoveTrendAfter, 'Value', strcmpi(handles.Detrend.AfterFilter, 'Yes'));
0217
0218
0219
0220 function Result=GetInputDirDisplayList(handles)
0221 Result ={};
0222 for x=size(handles.Cfg.DataDirs, 1):-1:1
0223 Result =[{sprintf('%d# %s',handles.Cfg.DataDirs{x, 2},handles.Cfg.DataDirs{x, 1})} ;Result];
0224 end
0225
0226
0227 function [nVolumn]=CheckDataDir(ADataDir)
0228 theFilenames = dir(ADataDir);
0229 theHdrFiles=dir(fullfile(ADataDir,'*.hdr'));
0230 theImgFiles=dir(fullfile(ADataDir,'*.img'));
0231
0232
0233
0234
0235
0236
0237
0238 if ~length(theHdrFiles)==length(theImgFiles)
0239 nVolumn =-1;
0240 fprintf('%s, *.{hdr,img} should be pairwise. Please re-examin them.\n', ADataDir);
0241 errordlg('*.{hdr,img} should be pairwise. Please re-examin them.');
0242 return;
0243 end
0244 count = 3; nVolumn = 0;
0245 for count = 3:size(struct2cell(theFilenames),2)
0246 if (length(theFilenames(count).name)>4) && ...
0247 strcmpi(theFilenames(count).name(end-3:end) , '.hdr')
0248 if strcmpi(theFilenames(count).name(1:end-4) ...
0249 , theFilenames(count+1).name(1:end-4) )
0250 nVolumn = nVolumn + 1;
0251 else
0252
0253 nVolumn =-1;
0254 fprintf('%s, *.{hdr,img} should be pairwise. Please re-examin them.\n', ADataDir);
0255 errordlg('*.{hdr,img} should be pairwise. Please re-examin them.');
0256 break;
0257 end
0258 end
0259 end
0260
0261
0262
0263 function btnComputeAlff_Callback(hObject, eventdata, handles)
0264 if (size(handles.Cfg.DataDirs, 1)==0)
0265 errordlg('No Data found! Please re-config');
0266 return;
0267 end
0268 if (exist('alff.m','file')==2)
0269
0270 handles.Log.Filename =GetLogFilename(handles.Cfg.OutputDir, get(handles.edtPrefix, 'String'));
0271 Log2File(handles);
0272 handles.Performance =cputime;
0273
0274 theOldDir =pwd;
0275 theOldColor=get(hObject,'BackgroundColor');
0276 set(hObject,'Enable','off', 'BackgroundColor', 'red');
0277 drawnow;
0278 try
0279
0280 if strcmpi(handles.Filter.UseFilter, 'Yes') && strcmpi(handles.Detrend.BeforeFilter, 'Yes'),
0281 Detrend(hObject, handles);
0282
0283 handles =guidata(hObject);
0284 end
0285
0286
0287
0288 if strcmpi(handles.Filter.UseFilter, 'Yes')
0289 BandPass(hObject, handles);
0290
0291 handles =guidata(hObject);
0292 end
0293
0294
0295 if strcmpi(handles.Filter.UseFilter, 'Yes') && strcmpi(handles.Detrend.AfterFilter, 'Yes'),
0296 Detrend(hObject, handles);
0297
0298 handles =guidata(hObject);
0299 end
0300
0301
0302 for x=1:size(handles.Cfg.DataDirs, 1)
0303
0304 set(handles.listDataDirs, 'Value', x);
0305 drawnow;
0306 if size(handles.Cfg.DataDirs, 1)>1,
0307 rest_waitbar((x-1)/size(handles.Cfg.DataDirs, 1)+0.01, ...
0308 handles.Cfg.DataDirs{x, 1}, ...
0309 'ALFF Computing','Parent');
0310 end
0311 fprintf('\nALFF :"%s"\n', handles.Cfg.DataDirs{x, 1});
0312
0313 theOutputDir=get(handles.edtOutputDir, 'String');
0314 thePrefix =get(handles.edtPrefix, 'String');
0315 theDstFile=fullfile(theOutputDir,[thePrefix '_' ...
0316 GetDirName(handles.Cfg.DataDirs{x, 1}) ] );
0317
0318 alff( handles.Cfg.DataDirs{x, 1}, ...
0319 handles.ALFF.SamplePeriod, ...
0320 handles.ALFF.BandHigh, ...
0321 handles.ALFF.BandLow, ...
0322 handles.Cfg.MaskFile, ...
0323 theDstFile);
0324
0325
0326 if strcmpi(handles.Cfg.WantMeanAlffMap, 'Yes')
0327 theOrigAlffMap =theDstFile;
0328 theMeanAlffMap =fullfile(theOutputDir,['m' thePrefix '_' ...
0329 GetDirName(handles.Cfg.DataDirs{x, 1}) ] );
0330 theMaskFile =handles.Cfg.MaskFile;
0331 rest_DivideMeanWithinMask(theOrigAlffMap, theMeanAlffMap, theMaskFile);
0332 end
0333 end
0334 handles.Performance =cputime -handles.Performance;
0335 LogPerformance(handles);
0336 catch
0337 rest_misc( 'DisplayLastException');
0338 errordlg(sprintf('Exception occured: \n\n%s' , lasterr));
0339 end
0340 cd(theOldDir);
0341 set(hObject,'Enable','on', 'BackgroundColor', theOldColor);
0342 drawnow;
0343 rest_waitbar;
0344 else
0345 errordlg('No alff.m ! Please re-install');
0346 end
0347
0348
0349
0350 function edtMaskfile_Callback(hObject, eventdata, handles)
0351 theMaskfile =get(hObject, 'String');
0352 if rest_misc('GetMatlabVersion')>=7.3,
0353 theMaskfile =strtrim(theMaskfile);
0354 end
0355 if exist(theMaskfile, 'file')
0356 handles.Cfg.MaskFile =theMaskfile;
0357 guidata(hObject, handles);
0358 else
0359 errordlg(sprintf('The mask file "%s" does not exist!\n Please re-check it.', theMaskfile));
0360 end
0361
0362 function edtMaskfile_CreateFcn(hObject, eventdata, handles)
0363 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0364 set(hObject,'BackgroundColor','white');
0365 end
0366
0367
0368 function btnSelectMask_Callback(hObject, eventdata, handles)
0369 [filename, pathname] = uigetfile({'*.img;*.mat', 'All Mask files (*.img; *.mat)'; ...
0370 '*.mat','MAT masks (*.mat)'; ...
0371 '*.img', 'ANALYZE or NIFTI masks(*.img)'}, ...
0372 'Pick a user''s mask');
0373 if ~(filename==0)
0374 handles.Cfg.MaskFile =[pathname filename];
0375 guidata(hObject,handles);
0376 elseif ~( exist(handles.Cfg.MaskFile, 'file')==2)
0377 set(handles.rbtnDefaultMask, 'Value',[1]);
0378 set(handles.rbtnUserMask, 'Value',[0]);
0379 set(handles.edtMaskfile, 'Enable','off');
0380 set(handles.btnSelectMask, 'Enable','off');
0381 handles.Cfg.MaskFile ='Default';
0382 guidata(hObject, handles);
0383 end
0384 UpdateDisplay(handles);
0385
0386
0387
0388
0389
0390 function rbtnDefaultMask_Callback(hObject, eventdata, handles)
0391 set(handles.edtMaskfile, 'Enable','off', 'String','Use Default Mask');
0392 set(handles.btnSelectMask, 'Enable','off');
0393 drawnow;
0394 handles.Cfg.MaskFile ='Default';
0395 guidata(hObject, handles);
0396 set(handles.rbtnDefaultMask,'Value',1);
0397 set(handles.rbtnNullMask,'Value',0);
0398 set(handles.rbtnUserMask,'Value',0);
0399
0400 function rbtnUserMask_Callback(hObject, eventdata, handles)
0401 set(handles.edtMaskfile,'Enable','on', 'String',handles.Cfg.MaskFile);
0402 set(handles.btnSelectMask, 'Enable','on');
0403 set(handles.rbtnDefaultMask,'Value',0);
0404 set(handles.rbtnNullMask,'Value',0);
0405 set(handles.rbtnUserMask,'Value',1);
0406 drawnow;
0407
0408 function rbtnNullMask_Callback(hObject, eventdata, handles)
0409 set(handles.edtMaskfile, 'Enable','off', 'String','Don''t use any Mask');
0410 set(handles.btnSelectMask, 'Enable','off');
0411 drawnow;
0412 handles.Cfg.MaskFile ='';
0413 guidata(hObject, handles);
0414 set(handles.rbtnDefaultMask,'Value',0);
0415 set(handles.rbtnNullMask,'Value',1);
0416 set(handles.rbtnUserMask,'Value',0);
0417
0418
0419
0420
0421
0422 function listDataDirs_Callback(hObject, eventdata, handles)
0423 theIndex =get(hObject, 'Value');
0424 if isempty(theIndex) || theIndex<1,
0425 msgbox(sprintf('Nothing added.\n\nYou must add some diretories containing only paired {hdr/img} files first'), ...
0426 'REST' ,'help');
0427 return;
0428 end
0429
0430 if strcmp(get(handles.figAlffMain, 'SelectionType'), 'open')
0431 msgbox(sprintf('%s \t\nhas\t %d\t volumes\n\nTotal: %d Data Directories' , ...
0432 handles.Cfg.DataDirs{theIndex, 1} , ...
0433 handles.Cfg.DataDirs{theIndex, 2} , ...
0434 size(handles.Cfg.DataDirs,1)), ...
0435 'Volume count in selected dir' ,'help');
0436 end
0437
0438 function listDataDirs_KeyPressFcn(hObject, eventdata, handles)
0439
0440 key =get(handles.figAlffMain, 'currentkey');
0441 if seqmatch({key},{'delete', 'backspace'})
0442 DeleteSelectedDataDir(hObject, eventdata,handles);
0443 end
0444
0445 function DeleteSelectedDataDir(hObject, eventdata, handles)
0446 theIndex =get(handles.listDataDirs, 'Value');
0447 if prod(size(handles.Cfg.DataDirs))==0 ...
0448 || size(handles.Cfg.DataDirs, 1)==0 ...
0449 || theIndex>size(handles.Cfg.DataDirs, 1),
0450 return;
0451 end
0452 theDir =handles.Cfg.DataDirs{theIndex, 1};
0453 theVolumnCount=handles.Cfg.DataDirs{theIndex, 2};
0454 tmpMsg=sprintf('Delete\n\n "%s" \nVolumn Count :%d ?', theDir, theVolumnCount);
0455 if strcmp(questdlg(tmpMsg, 'Delete confirmation'), 'Yes')
0456 if theIndex>1,
0457 set(handles.listDataDirs, 'Value', theIndex-1);
0458 end
0459 handles.Cfg.DataDirs(theIndex, :)=[];
0460 if size(handles.Cfg.DataDirs, 1)==0
0461 handles.Cfg.DataDirs={};
0462 end
0463 guidata(hObject, handles);
0464 UpdateDisplay(handles);
0465 end
0466
0467 function ClearDataDirectories(hObject, eventdata, handles)
0468 if prod(size(handles.Cfg.DataDirs))==0 ...
0469 || size(handles.Cfg.DataDirs, 1)==0,
0470 return;
0471 end
0472 tmpMsg=sprintf('Attention!\n\n\nDelete all data directories?');
0473 if strcmpi(questdlg(tmpMsg, 'Clear confirmation'), 'Yes'),
0474 handles.Cfg.DataDirs(:)=[];
0475 if prod(size(handles.Cfg.DataDirs))==0,
0476 handles.Cfg.DataDirs={};
0477 end
0478 guidata(hObject, handles);
0479 UpdateDisplay(handles);
0480 end
0481
0482 function listDataDirs_CreateFcn(hObject, eventdata, handles)
0483 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0484 set(hObject,'BackgroundColor','white');
0485 end
0486
0487
0488 function edtPrefix_Callback(hObject, eventdata, handles)
0489
0490
0491 function edtPrefix_CreateFcn(hObject, eventdata, handles)
0492 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0493 set(hObject,'BackgroundColor','white');
0494 end
0495
0496
0497
0498
0499 function edtOutputDir_Callback(hObject, eventdata, handles)
0500 theDir =get(hObject, 'String');
0501 SetOutputDir(hObject,handles, theDir);
0502
0503 function edtOutputDir_CreateFcn(hObject, eventdata, handles)
0504 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0505 set(hObject,'BackgroundColor','white');
0506 end
0507
0508
0509 function btnSelectOutputDir_Callback(hObject, eventdata, handles)
0510 theDir =handles.Cfg.OutputDir;
0511 theDir =uigetdir(theDir, 'Please select the data directory to compute alff map: ');
0512 if ~isequal(theDir, 0)
0513 SetOutputDir(hObject,handles, theDir);
0514 end
0515
0516 function SetOutputDir(hObject, handles, ADir)
0517 if 7==exist(ADir,'dir')
0518 handles.Cfg.OutputDir =ADir;
0519 guidata(hObject, handles);
0520 UpdateDisplay(handles);
0521 end
0522
0523 function Result=GetDirName(ADir)
0524 if isempty(ADir), Result=ADir; return; end
0525 theDir =ADir;
0526 if strcmp(theDir(end),filesep)==1
0527 theDir=theDir(1:end-1);
0528 end
0529 [tmp,Result]=fileparts(theDir);
0530
0531
0532 function ckboxFilter_Callback(hObject, eventdata, handles)
0533 if get(hObject,'Value')
0534 handles.Filter.UseFilter ='Yes';
0535 else
0536 handles.Filter.UseFilter ='No';
0537 end
0538 guidata(hObject, handles);
0539 UpdateDisplay(handles);
0540
0541 function edtBandLow_Callback(hObject, eventdata, handles)
0542 handles.Filter.BandLow =str2double(get(hObject,'String'));
0543 guidata(hObject, handles);
0544
0545 function edtBandLow_CreateFcn(hObject, eventdata, handles)
0546 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0547 set(hObject,'BackgroundColor','white');
0548 end
0549
0550
0551 function edtBandHigh_Callback(hObject, eventdata, handles)
0552 handles.Filter.BandHigh =str2double(get(hObject,'String'));
0553 guidata(hObject, handles);
0554
0555 function edtBandHigh_CreateFcn(hObject, eventdata, handles)
0556 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0557 set(hObject,'BackgroundColor','white');
0558 end
0559
0560
0561
0562 function ckboxRetrend_Callback(hObject, eventdata, handles)
0563 if get(hObject,'Value')
0564 handles.Filter.Retrend ='Yes';
0565 else
0566 handles.Filter.Retrend ='No';
0567 end
0568 guidata(hObject, handles);
0569 UpdateDisplay(handles);
0570
0571 function edtSamplePeriod_Callback(hObject, eventdata, handles)
0572 handles.Filter.SamplePeriod =str2double(get(hObject,'String'));
0573 guidata(hObject, handles);
0574
0575 function edtSamplePeriod_CreateFcn(hObject, eventdata, handles)
0576 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0577 set(hObject,'BackgroundColor','white');
0578 end
0579
0580
0581 function ckboxDivideMean_Callback(hObject, eventdata, handles)
0582 if get(hObject,'Value')
0583 handles.Cfg.WantMeanAlffMap ='Yes';
0584 else
0585 handles.Cfg.WantMeanAlffMap ='No';
0586 end
0587 guidata(hObject, handles);
0588 UpdateDisplay(handles);
0589
0590 function btnDivideMean_Callback(hObject, eventdata, handles)
0591 theOldColor=get(hObject,'BackgroundColor');
0592 set(hObject,'Enable','off', 'BackgroundColor', 'red');
0593 drawnow;
0594 try
0595 [filename, pathname] = uigetfile({'*.img', 'alff files (*.img)'}, ...
0596 'Pick one alff map');
0597 if (filename~=0)
0598 if strcmpi(filename(end-3:end), '.img')
0599 filename = filename(1:end-4);
0600 end
0601 if ~strcmpi(pathname(end), filesep)
0602 pathname = [pathname filesep];
0603 end
0604 theOrigAlffMap =[pathname filename];
0605 theMeanAlffMap =[pathname 'm' filename];
0606 theMaskFile =handles.Cfg.MaskFile;
0607 rest_DivideMeanWithinMask(theOrigAlffMap, theMeanAlffMap, theMaskFile);
0608 msgbox(sprintf('Alff brain "%s.{hdr/img}" \ndivide its mean within mask successfully.\t\n\nSave to "%s.{hdr/img}"\n' , ...
0609 theOrigAlffMap, theMeanAlffMap), ...
0610 'Divide mean within mask successfully' ,'help');
0611 end
0612 catch
0613 rest_misc( 'DisplayLastException');
0614 end
0615 set(hObject,'Enable','on', 'BackgroundColor', theOldColor);
0616 drawnow;
0617
0618 function btnBandPass_Callback(hObject, eventdata, handles)
0619 theOldColor=get(hObject,'BackgroundColor');
0620 set(hObject,'Enable','off', 'BackgroundColor', 'red');
0621 drawnow;
0622 try
0623
0624 if strcmpi(handles.Filter.UseFilter, 'Yes')
0625 BandPass(hObject, handles);
0626 msgbox('Ideal Band Pass filter Over.',...
0627 'Filter successfully' ,'help');
0628 else
0629 errordlg(sprintf('You didn''t select option "Band Pass". \n\nPlease slect first.'));
0630 end
0631 UpdateDisplay(handles);
0632 catch
0633 rest_misc( 'DisplayLastException');
0634 end
0635 rest_waitbar;
0636 set(hObject,'Enable','on', 'BackgroundColor', theOldColor);
0637 drawnow;
0638
0639 function InitFrames(hObject,handles)
0640 offsetY =83;
0641
0642 uicontrol(handles.figAlffMain, 'Style','Frame','Position',[2 offsetY+152 433 1]);
0643 uicontrol(handles.figAlffMain, 'Style','Frame','Position',[2 offsetY+202 433 1]);
0644 uicontrol(handles.figAlffMain, 'Style','Frame','Position',[90 offsetY+291 343 1]);
0645 uicontrol(handles.figAlffMain, 'Style','Frame','Position',[90 offsetY+202 1 90]);
0646 uicontrol(handles.figAlffMain, 'Style','Frame','Position',[2 offsetY+152 1 280]);
0647 uicontrol(handles.figAlffMain, 'Style','Frame','Position',[435 offsetY+152 1 280]);
0648 uicontrol(handles.figAlffMain, 'Style','Frame','Position',[2 offsetY+432 433 1]);
0649 uicontrol(handles.figAlffMain,'Style','Text','Position',[152 offsetY+430 100 14],...
0650 'String','Input Parameters');
0651 uicontrol(handles.figAlffMain,'Style','Text','Position',[208 offsetY+288 40 14],...
0652 'String','Mask');
0653
0654 uicontrol(handles.figAlffMain, 'Style','Frame','Position',[2 offsetY+94 433 1]);
0655 uicontrol(handles.figAlffMain, 'Style','Frame','Position',[2 offsetY-8 433 1]);
0656 uicontrol(handles.figAlffMain, 'Style','Frame','Position',[2 offsetY-8 1 102]);
0657 uicontrol(handles.figAlffMain, 'Style','Frame','Position',[435 offsetY-8 1 102]);
0658 uicontrol(handles.figAlffMain,'Style','Text','Position',[152 offsetY+88 160 14],...
0659 'String','Output Parameters (ALFF map)');
0660
0661 uicontrol(handles.figAlffMain, 'Style','Frame','Position',[2 offsetY+450 433 1]);
0662 uicontrol(handles.figAlffMain, 'Style','Frame','Position',[435 offsetY+450 1 50]);
0663 uicontrol(handles.figAlffMain, 'Style','Frame','Position',[2 offsetY+450 1 50]);
0664 uicontrol(handles.figAlffMain, 'Style','Frame','Position',[2 offsetY+500 433 1]);
0665 uicontrol(handles.figAlffMain,'Style','Text','Position',[142 offsetY+495 180 14],...
0666 'String','Option: Ideal Band Pass Filter');
0667
0668 uicontrol(handles.figAlffMain, 'Style','Frame','Position',[2 offsetY+515 433 1]);
0669 uicontrol(handles.figAlffMain, 'Style','Frame','Position',[435 offsetY+515 1 50]);
0670 uicontrol(handles.figAlffMain, 'Style','Frame','Position',[2 offsetY+515 1 50]);
0671 uicontrol(handles.figAlffMain, 'Style','Frame','Position',[2 offsetY+565 433 1]);
0672 uicontrol(handles.figAlffMain,'Style','Text','Position',[142 offsetY+555 180 14],...
0673 'String','Option: Remove Linear Trend');
0674
0675
0676
0677 uicontrol(handles.figAlffMain, 'Style','Frame','Position',[2 offsetY-25 433 1]);
0678 uicontrol(handles.figAlffMain,'Style','Text','Position',[152 offsetY-30 140 14],...
0679 'String','Manual Operations');
0680
0681
0682 function InitControlProperties(hObject, handles)
0683
0684
0685 set(handles.figAlffMain,...
0686 'Units', 'pixels', ...
0687 'Position', [20 5 440 650], ...
0688 'Name', 'alff_gui', ...
0689 'MenuBar', 'none', ...
0690 'NumberTitle', 'off', ...
0691 'Color', get(0,'DefaultUicontrolBackgroundColor'));
0692
0693
0694 set(handles.txtAlff, ...
0695 'Style', 'text', ...
0696 'Units', 'pixels', ...
0697 'Position', [16 186 91 40], ...
0698 'FontSize', 24, ...
0699 'FontWeight', 'bold', ...
0700 'String', 'ALFF');
0701
0702 theFontSize =8;
0703 if isunix, theFontSize =10; end
0704 set(handles.txtAlffLongName, ...
0705 'Style', 'text', ...
0706 'Units', 'pixels', ...
0707 'Position', [10 300 65 76], ...
0708 'FontSize', theFontSize, ...
0709 'FontWeight', 'normal', ...
0710 'Enable', 'off', ...
0711 'String', sprintf('Amplitude\nof Low\nFrequency\nFluctuation\nComputation'));
0712
0713 set(handles.txtOutputDir, ...
0714 'Style', 'text', ...
0715 'Units', 'pixels', ...
0716 'Position', [8 109 80 21], ...
0717 'FontSize', theFontSize, ...
0718 'String', 'Directory:');
0719
0720 set(handles.txtInputDir, ...
0721 'Style', 'text', ...
0722 'Units', 'pixels', ...
0723 'Position', [7 386 80 21], ...
0724 'String', 'Data Directory:');
0725
0726 set(handles.txtPrefix, ...
0727 'Style', 'text', ...
0728 'Units', 'pixels', ...
0729 'Position', [9 140 80 21], ...
0730 'String', 'Prefix:');
0731
0732 set(handles.txtResultFilename, ...
0733 'Style', 'text', ...
0734 'Units', 'pixels', ...
0735 'Position', [227 148 200 16], ...
0736 'HorizontalAlignment','left' , ...
0737 'String', 'Result: Prefix_DirectoryName.{hdr/img}');
0738
0739 set(handles.txtBandSep, ...
0740 'Style', 'text', ...
0741 'Units', 'pixels', ...
0742 'Position', [146 526 25 51], ...
0743 'FontSize', 28, ...
0744 'String', '~');
0745
0746 set(handles.txtTR, ...
0747 'Style', 'text', ...
0748 'Units', 'pixels', ...
0749 'Position', [230 540 40 16], ...
0750 'String', 'TR: (s)');
0751
0752 set(handles.txtAlffBand, ...
0753 'Style', 'text', ...
0754 'Units', 'pixels', ...
0755 'Position', [20 245 50 16], ...
0756 'String', 'Band( Hz)');
0757
0758 set(handles.txtAlffBandSep, ...
0759 'Style', 'text', ...
0760 'Units', 'pixels', ...
0761 'Position', [144 230 25 51], ...
0762 'FontSize', 28, ...
0763 'String', '~');
0764
0765 set(handles.txtAlffTR, ...
0766 'Style', 'text', ...
0767 'Units', 'pixels', ...
0768 'Position', [230 245 40 16], ...
0769 'String', 'TR: (s)');
0770
0771
0772
0773 set(handles.btnSelectOutputDir, ...
0774 'Style', 'pushbutton', ...
0775 'Units', 'pixels', ...
0776 'Position', [396 107 30 25], ...
0777 'FontSize', 18, ...
0778 'String', '...');
0779
0780 set(handles.btnSelectDataDir, ...
0781 'Style', 'pushbutton', ...
0782 'Units', 'pixels', ...
0783 'Position', [396 384 30 25], ...
0784 'FontSize', 18, ...
0785 'String', '...', ...
0786 'CData', zeros(1,0));
0787
0788 set(handles.btnSelectMask, ...
0789 'Style', 'pushbutton', ...
0790 'Units', 'pixels', ...
0791 'Position', [396 290 30 25], ...
0792 'FontSize', 18, ...
0793 'String', '...', ...
0794 'Enable', 'off', ...
0795 'CData', zeros(1,0));
0796
0797 set(handles.btnComputeAlff, ...
0798 'Style', 'pushbutton', ...
0799 'Units', 'pixels', ...
0800 'Position', [320 186 107 33], ...
0801 'FontSize', 12, ...
0802 'FontWeight', 'bold', ...
0803 'String', 'Do all');
0804
0805
0806 set(handles.btnDetrend , ...
0807 'Style', 'pushbutton', ...
0808 'Units', 'pixels', ...
0809 'Position', [337 603 90 25], ...
0810 'FontSize', 10, ...
0811 'Enable', 'off', ...
0812 'String', 'Detrend');
0813 set(handles.btnBandPass , ...
0814 'Style', 'pushbutton', ...
0815 'Units', 'pixels', ...
0816 'Position', [337 540 90 25], ...
0817 'FontSize', 10, ...
0818 'Enable', 'off', ...
0819 'String', 'Filter');
0820 set(handles.btnAlffBandDetail , ...
0821 'Style', 'pushbutton', ...
0822 'Units', 'pixels', ...
0823 'Position', [337 244 90 25], ...
0824 'FontSize', 10, ...
0825 'String', 'Band Hint');
0826
0827
0828 set(handles.btnHelp, ...
0829 'Style', 'pushbutton', ...
0830 'Units', 'pixels', ...
0831 'Position', [10 10 90 33], ...
0832 'FontSize', 10, ...
0833 'String', 'Help');
0834 set(handles.btnDivideMean, ...
0835 'Style', 'pushbutton', ...
0836 'Units', 'pixels', ...
0837 'Position', [110 10 90 33], ...
0838 'FontSize', 10, ...
0839 'String', 'Divide Mean');
0840 set(handles.btnSliceViewer, ...
0841 'Style', 'pushbutton', ...
0842 'Units', 'pixels', ...
0843 'Position', [210 10 90 33], ...
0844 'FontSize', 10, ...
0845 'String', 'Slice Viewer');
0846 set(handles.btnWaveGraph, ...
0847 'Style', 'pushbutton', ...
0848 'Units', 'pixels', ...
0849 'Position', [314 10 110 33], ...
0850 'FontSize', 10, ...
0851 'String', 'Power Spectrum');
0852
0853
0854
0855 set(handles.rbtnDefaultMask, ...
0856 'Style', 'radiobutton', ...
0857 'Units', 'pixels', ...
0858 'Position', [110 347 158 16], ...
0859 'String', 'Default mask');
0860
0861 set(handles.rbtnUserMask, ...
0862 'Style', 'radiobutton', ...
0863 'Units', 'pixels', ...
0864 'Position', [110 321 148 16], ...
0865 'String', 'User''s defined mask');
0866
0867 set(handles.rbtnNullMask, ...
0868 'Style', 'radiobutton', ...
0869 'Units', 'pixels', ...
0870 'Position', [277 348 82 16], ...
0871 'String', 'No mask');
0872
0873
0874 set(handles.ckboxFilter, ...
0875 'Style', 'checkbox', ...
0876 'Units', 'pixels', ...
0877 'Position', [14 540 80 22], ...
0878 'String', 'Band (Hz)');
0879
0880 set(handles.ckboxDivideMean, ...
0881 'Style', 'checkbox', ...
0882 'Units', 'pixels', ...
0883 'Position', [12 82 430 19], ...
0884 'String', 'Divide ALFF brain by the mean within the mask (mPrefix_DirectoryName.{hdr/img})');
0885
0886 set(handles.ckboxRetrend, ...
0887 'Style', 'checkbox', ...
0888 'Units', 'pixels', ...
0889 'Position', [366 540 60 22], ...
0890 'Enable', 'Off', ...
0891 'String', 'Retrend');
0892
0893 set(handles.ckboxRemoveTrendBefore, ...
0894 'Style', 'checkbox', ...
0895 'Units', 'pixels', ...
0896 'Position', [13 605 140 21],...
0897 'String', 'detrend');
0898 set(handles.ckboxRemoveTrendAfter, ...
0899 'Style', 'checkbox', ...
0900 'Units', 'pixels', ...
0901 'Position', [171 605 140 21],...
0902 'Visible', 'off', ...
0903 'String', 'detrend AFTER Filter');
0904
0905
0906 set(handles.edtOutputDir, ...
0907 'Style', 'edit', ...
0908 'Units', 'pixels', ...
0909 'Position', [94 109 300 23], ...
0910 'BackgroundColor', [1 1 1], ...
0911 'String', 'Edit Text');
0912
0913 set(handles.edtDataDirectory, ...
0914 'Style', 'edit', ...
0915 'Units', 'pixels', ...
0916 'Position', [94 386 300 22], ...
0917 'BackgroundColor', [1 1 1], ...
0918 'String', '');
0919
0920 set(handles.edtMaskfile, ...
0921 'Style', 'edit', ...
0922 'Units', 'pixels', ...
0923 'Position', [94 290 300 23], ...
0924 'BackgroundColor', [1 1 1], ...
0925 'String', 'Edit Text', ...
0926 'Enable', 'off');
0927
0928 set(handles.edtPrefix, ...
0929 'Style', 'edit', ...
0930 'Units', 'pixels', ...
0931 'Position', [94 142 115 22], ...
0932 'BackgroundColor', [1 1 1], ...
0933 'String', 'ALFFMap');
0934
0935 set(handles.edtBandLow, ...
0936 'Style', 'edit', ...
0937 'Units', 'pixels', ...
0938 'Position', [94 541 50 22], ...
0939 'BackgroundColor', [1 1 1], ...
0940 'String', '0.01', ...
0941 'Enable', 'off');
0942
0943 set(handles.edtBandHigh, ...
0944 'Style', 'edit', ...
0945 'Units', 'pixels', ...
0946 'Position', [171 541 50 22], ...
0947 'BackgroundColor', [1 1 1], ...
0948 'String', '0.08', ...
0949 'Enable', 'off');
0950
0951 set(handles.edtSamplePeriod, ...
0952 'Style', 'edit', ...
0953 'Units', 'pixels', ...
0954 'Position', [276 541 50 22], ...
0955 'BackgroundColor', [1 1 1], ...
0956 'String', '2', ...
0957 'Enable', 'off');
0958
0959 set(handles.edtAlffBandLow, ...
0960 'Style', 'edit', ...
0961 'Units', 'pixels', ...
0962 'Position', [94 245 50 22], ...
0963 'BackgroundColor', [1 1 1], ...
0964 'String', '0.01', ...
0965 'Enable', 'on');
0966
0967 set(handles.edtAlffBandHigh, ...
0968 'Style', 'edit', ...
0969 'Units', 'pixels', ...
0970 'Position', [171 245 50 22], ...
0971 'BackgroundColor', [1 1 1], ...
0972 'String', '0.08', ...
0973 'Enable', 'on');
0974
0975 set(handles.edtAlffSamplePeriod, ...
0976 'Style', 'edit', ...
0977 'Units', 'pixels', ...
0978 'Position', [276 245 50 22], ...
0979 'BackgroundColor', [1 1 1], ...
0980 'String', '2', ...
0981 'Enable', 'on');
0982
0983
0984
0985 set(handles.listDataDirs, ...
0986 'Style', 'listbox', ...
0987 'Units', 'pixels', ...
0988 'Position', [14 413 413 98], ...
0989 'BackgroundColor', [1 1 1], ...
0990 'String', '');
0991
0992
0993 handles.hContextMenu =uicontextmenu;
0994 set(handles.listDataDirs, 'UIContextMenu', handles.hContextMenu);
0995 uimenu(handles.hContextMenu, 'Label', 'Add a directory', 'Callback', get(handles.btnSelectDataDir, 'Callback'));
0996 uimenu(handles.hContextMenu, 'Label', 'Remove selected directory', 'Callback', 'alff_gui(''DeleteSelectedDataDir'',gcbo,[], guidata(gcbo))');
0997 uimenu(handles.hContextMenu, 'Label', 'Add recursively all sub-folders of a directory', 'Callback', 'alff_gui(''RecursiveAddDataDir'',gcbo,[], guidata(gcbo))');
0998 uimenu(handles.hContextMenu, 'Label', '=============================');
0999 uimenu(handles.hContextMenu, 'Label', 'Clear all data directories', 'Callback', 'alff_gui(''ClearDataDirectories'',gcbo,[], guidata(gcbo))');
1000
1001
1002
1003 guidata(hObject,handles);
1004
1005
1006 function Log2File(handles)
1007 constLineSep= '-------------------------------------------------------------------------------';
1008 [theVer, theRelease] =rest_misc( 'GetRestVersion');
1009 theMsgVersion = sprintf('REST Version:%s, Release %s\r\n%s\r\n', theVer, theRelease, constLineSep);
1010 theMsgHead = sprintf('ALFF computation log %s\r\n%s\r\n', rest_misc( 'GetDateTimeStr'), constLineSep);
1011 theMsg =sprintf('%s\r\n%s\r\n\r\n%s', theMsgVersion, theMsgHead, constLineSep);
1012 theMsg =sprintf('%s\r\nRemove Linear Trend options:\r\n%s\r\n\r\n%s',theMsg,...
1013 LogRemoveLinearTrend(handles), constLineSep);
1014 theMsg =sprintf('%s\r\nIdeal Band Pass filter options:\r\n%s\r\n\r\n%s',theMsg,...
1015 LogBandPassFilter(handles), constLineSep);
1016 theMsg =sprintf('%s\r\nALFF input parameters:\r\n%s\r\n\r\n%s', theMsg, ...
1017 LogInputParameters(handles), constLineSep);
1018 theMsg =sprintf('%s\r\nALFF Band Config:\r\n%s\r\n\r\n%s',theMsg,...
1019 LogALFFParameters(handles), constLineSep);
1020 theMsg =sprintf('%s\r\nALFF output parameters:\r\n%s\r\n\r\n%s', theMsg, ...
1021 LogOutputParameters(handles), constLineSep);
1022
1023 fid = fopen(handles.Log.Filename,'w');
1024 if fid~=-1
1025 fprintf(fid,'%s',theMsg);
1026 fclose(fid);
1027 else
1028 errordlg(sprintf('Error to open log file:\n\n%s', handles.Log.Filename));
1029 end
1030
1031 function ResultLogString=LogRemoveLinearTrend(handles)
1032 ResultLogString ='';
1033 ResultLogString =sprintf('%s\tremove linear trend BEFORE filter: %s\r\n',ResultLogString, handles.Detrend.BeforeFilter);
1034 ResultLogString =sprintf('%s\tremove linear trend AFTER filter: %s\r\n',ResultLogString, handles.Detrend.AfterFilter);
1035
1036 function ResultLogString=LogBandPassFilter(handles)
1037 ResultLogString ='';
1038 ResultLogString =sprintf('%s\tUse Filter: %s\r\n',ResultLogString, handles.Filter.UseFilter);
1039 ResultLogString =sprintf('%s\tBand Low: %g\r\n', ResultLogString, handles.Filter.BandLow);
1040 ResultLogString =sprintf('%s\tBand High: %g\r\n',ResultLogString, handles.Filter.BandHigh);
1041 ResultLogString =sprintf('%s\tSample Period(i.e. TR): %g\r\n',ResultLogString, handles.Filter.SamplePeriod);
1042
1043 function ResultLogString=LogALFFParameters(handles)
1044 ResultLogString ='';
1045 ResultLogString =sprintf('%s\tBand Low: %g\r\n', ResultLogString, handles.ALFF.BandLow);
1046 ResultLogString =sprintf('%s\tBand High: %g\r\n',ResultLogString, handles.ALFF.BandHigh);
1047 ResultLogString =sprintf('%s\tSample Period(i.e. TR): %g\r\n',ResultLogString, handles.ALFF.SamplePeriod);
1048
1049 function ResultLogString=LogInputParameters(handles)
1050 ResultLogString ='';
1051 constLineSep= '-------------------------------------------------------------------------------';
1052 theDataDirString= '';
1053 theDataDirCells =get(handles.listDataDirs, 'string');
1054 for x=1:length(theDataDirCells)
1055 theDataDirString =sprintf('%s\r\n\t%s', theDataDirString, theDataDirCells{x});
1056 end
1057 theDirType ='';
1058 if strcmpi(handles.Detrend.BeforeFilter, 'Yes')
1059 theDirType =sprintf(' %s after Detrend processing', theDirType);
1060 end
1061 if strcmpi(handles.Detrend.BeforeFilter, 'Yes') && ...
1062 strcmpi(handles.Filter.UseFilter, 'Yes'),
1063 theDirType =sprintf(' %s and ', theDirType);
1064 end
1065 if strcmpi(handles.Filter.UseFilter, 'Yes')
1066 theDirType =sprintf(' %s after Filter processing', theDirType);
1067 end
1068 ResultLogString =sprintf('%s\tInput Data Directories( %s): \r\n\t%s%s\r\n\t%s\r\n',ResultLogString,...
1069 theDirType, ...
1070 constLineSep, ...
1071 theDataDirString, ...
1072 constLineSep);
1073 ResultLogString =sprintf('%s\tMask file: %s\r\n', ResultLogString, handles.Cfg.MaskFile);
1074
1075 function ResultLogString=LogOutputParameters(handles)
1076 ResultLogString ='';
1077 ResultLogString =sprintf('%s\tPrefix to the Data directories: %s\r\n',ResultLogString, get(handles.edtPrefix, 'String'));
1078 ResultLogString =sprintf('%s\tOutput Data Directories: %s\r\n',ResultLogString, handles.Cfg.OutputDir);
1079 ResultLogString =sprintf('%s\tWant mean ReHo map computation: %s \r\n',ResultLogString, handles.Cfg.WantMeanAlffMap);
1080
1081
1082
1083 function LogPerformance(handles)
1084 theMsg =sprintf('\r\n\r\nTotal elapsed time for ALFF Computing: %g seconds\r\n',handles.Performance);
1085 fid = fopen(handles.Log.Filename,'r+');
1086 fseek(fid, 0, 'eof');
1087 if fid~=-1
1088 fprintf(fid,'%s',theMsg);
1089 fclose(fid);
1090 else
1091 errordlg(sprintf('Error to open log file:\n\n%s', handles.Log.Filename));
1092 end
1093
1094
1095
1096 function ResultLogFileName=GetLogFilename(ALogDirectory, APrefix)
1097 if isempty(ALogDirectory)
1098 [pathstr, name, ext, versn] = fileparts(mfilename('fullpath'));
1099 ALogDirectory =pathstr;
1100 end
1101 if ~strcmp(ALogDirectory(end), filesep)
1102 ALogDirectory =[ALogDirectory filesep];
1103 end
1104 ResultLogFileName=sprintf('%s%s_%s.log', ...
1105 ALogDirectory, ...
1106 APrefix, ...
1107 rest_misc( 'GetDateTimeStr'));
1108
1109
1110 function btnSliceViewer_Callback(hObject, eventdata, handles)
1111
1112 theOldColor=get(hObject,'BackgroundColor');
1113 set(hObject,'Enable','off', 'BackgroundColor', 'red');
1114 drawnow;
1115 try
1116 rest_sliceviewer;
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126 catch
1127 rest_misc( 'DisplayLastException');
1128 end
1129 set(hObject,'Enable','on', 'BackgroundColor', theOldColor);
1130 drawnow;
1131
1132
1133
1134 function btnWaveGraph_Callback(hObject, eventdata, handles)
1135
1136 theOldColor=get(hObject,'BackgroundColor');
1137 set(hObject,'Enable','off', 'BackgroundColor', 'red');
1138 drawnow;
1139 try
1140 [filename, pathname] = uigetfile({'*.img', 'ANALYZE or NIFTI files (*.img)'}, ...
1141 'Pick one functional EPI brain map in the dataset''s directory');
1142 if any(filename~=0) && ischar(filename),
1143 if ~strcmpi(pathname(end), filesep)
1144 pathname = [pathname filesep];
1145 end
1146 theBrainMap =[pathname filename];
1147 theViewer =rest_sliceviewer('ShowImage', theBrainMap);
1148
1149
1150 theDataSetDir =pathname;
1151 theVoxelPosition=rest_sliceviewer('GetPosition', theViewer);
1152 theSamplePeriod =handles.ALFF.SamplePeriod;
1153 theBandRange =[handles.ALFF.BandLow, handles.ALFF.BandHigh];
1154 rest_powerspectrum('ShowFluctuation', theDataSetDir, theVoxelPosition, ...
1155 theSamplePeriod, theBandRange);
1156
1157
1158 theCallback ='';
1159 cmdDataSetDir =sprintf('theDataSetDir= ''%s'';', theDataSetDir);
1160 cmdBrainMap =sprintf('theVoxelPosition=rest_sliceviewer(''GetPosition'', %g);', theViewer);
1161 cmdSamplePeriod =sprintf('theSamplePeriod= %g;', theSamplePeriod);
1162 cmdBandRange =sprintf('theBandRange= [%g, %g];', theBandRange(1), theBandRange(2));
1163 cmdUpdateWaveGraph ='rest_powerspectrum(''ShowFluctuation'', theDataSetDir, theVoxelPosition, theSamplePeriod, theBandRange);';
1164 theCallback =sprintf('%s\n%s\n%s\n%s\n%s\n',cmdDataSetDir, ...
1165 cmdBrainMap, cmdSamplePeriod, cmdBandRange, ...
1166 cmdUpdateWaveGraph);
1167 cmdClearVar ='clear theDataSetDir theVoxelPosition theSamplePeriod theBandRange;';
1168 rest_sliceviewer('UpdateCallback', theViewer, [theCallback cmdClearVar], 'ALFF Analysis');
1169
1170
1171 theMsg =sprintf('TR( s): %g\nBand( Hz): %g~%g', ...
1172 theSamplePeriod, theBandRange(1), theBandRange(2) );
1173 rest_sliceviewer('SetMessage', theViewer, theMsg);
1174 end
1175 catch
1176 rest_misc( 'DisplayLastException');
1177 end
1178 set(hObject,'Enable','on', 'BackgroundColor', theOldColor);
1179 drawnow;
1180 rest_waitbar;
1181
1182
1183 function ckboxRemoveTrendBefore_Callback(hObject, eventdata, handles)
1184 if get(hObject,'Value')
1185 handles.Detrend.BeforeFilter ='Yes';
1186 else
1187 handles.Detrend.BeforeFilter ='No';
1188 end
1189 guidata(hObject, handles);
1190 UpdateDisplay(handles);
1191
1192 function ckboxRemoveTrendAfter_Callback(hObject, eventdata, handles)
1193 if get(hObject,'Value')
1194 handles.Detrend.AfterFilter ='Yes';
1195 else
1196 handles.Detrend.AfterFilter ='No';
1197 end
1198 guidata(hObject, handles);
1199 UpdateDisplay(handles);
1200
1201 function btnDetrend_Callback(hObject, eventdata, handles)
1202 theOldColor=get(hObject,'BackgroundColor');
1203 set(hObject,'Enable','off', 'BackgroundColor', 'red');
1204 drawnow;
1205 try
1206 Detrend(hObject,handles);
1207 msgbox('Remove the Linear Trend Over.',...
1208 'Detrend successfully' ,'help');
1209 catch
1210 rest_misc( 'DisplayLastException');
1211 end
1212 rest_waitbar;
1213 set(hObject,'Enable','on', 'BackgroundColor', theOldColor);
1214 drawnow;
1215
1216 function Detrend(hObject,handles)
1217 for x=1:size(handles.Cfg.DataDirs, 1)
1218
1219 set(handles.listDataDirs, 'Value', x);
1220 drawnow;
1221 if size(handles.Cfg.DataDirs, 1)>1,
1222 rest_waitbar((x-1)/size(handles.Cfg.DataDirs, 1)+0.01, ...
1223 handles.Cfg.DataDirs{x, 1}, ...
1224 'Removing the Linear Trend','Parent');
1225 end
1226 rest_detrend(handles.Cfg.DataDirs{x, 1}, '_detrend');
1227
1228
1229 handles.Cfg.DataDirs{x, 1}=[handles.Cfg.DataDirs{x, 1} , '_detrend'];
1230 guidata(hObject, handles);
1231 end
1232 UpdateDisplay(handles);
1233
1234
1235
1236 function edtAlffBandLow_Callback(hObject, eventdata, handles)
1237 handles.ALFF.BandLow =str2double(get(hObject,'String'));
1238 guidata(hObject, handles);
1239
1240 function edtAlffBandLow_CreateFcn(hObject, eventdata, handles)
1241 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1242 set(hObject,'BackgroundColor','white');
1243 end
1244
1245
1246 function edtAlffBandHigh_Callback(hObject, eventdata, handles)
1247 handles.ALFF.BandHigh =str2double(get(hObject,'String'));
1248 guidata(hObject, handles);
1249
1250 function edtAlffBandHigh_CreateFcn(hObject, eventdata, handles)
1251 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1252 set(hObject,'BackgroundColor','white');
1253 end
1254
1255
1256 function edtAlffSamplePeriod_Callback(hObject, eventdata, handles)
1257 handles.ALFF.SamplePeriod =str2double(get(hObject,'String'));
1258 guidata(hObject, handles);
1259
1260 function edtAlffSamplePeriod_CreateFcn(hObject, eventdata, handles)
1261 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
1262 set(hObject,'BackgroundColor','white');
1263 end
1264
1265
1266
1267
1268 function btnAlffBandDetail_Callback(hObject, eventdata, handles)
1269
1270 sampleLength =inputdlg('Please input sample length: (i.e. the total number of time points)', ...
1271 'ALFF Band Detailed Message');
1272 sampleLength =str2num(sampleLength{1});
1273 sampleFreq =1/handles.ALFF.SamplePeriod;
1274 paddedLength =rest_nextpow2_one35(sampleLength);
1275 freqPrecision =sampleFreq /paddedLength;
1276 BandLowIdx =handles.ALFF.BandLow * paddedLength * handles.ALFF.SamplePeriod;
1277 rBandLowIdx =round(BandLowIdx);
1278 rBandLow =rBandLowIdx /paddedLength /handles.ALFF.SamplePeriod;
1279 BandHighIdx =handles.ALFF.BandHigh * paddedLength * handles.ALFF.SamplePeriod;
1280 rBandHighIdx =round(BandHighIdx);
1281 rBandHigh =rBandHighIdx /paddedLength /handles.ALFF.SamplePeriod;
1282
1283 theWantBandInfo =sprintf('%gHz --> Index=%g, %gHz --> Index=%g', ...
1284 handles.ALFF.BandLow, BandLowIdx, ...
1285 handles.ALFF.BandHigh, BandHighIdx);
1286 theRealBandInfo =sprintf('%gHz --> Index=%g, %gHz --> Index=%g', ...
1287 rBandLow, rBandLowIdx, ...
1288 rBandHigh, rBandHighIdx);
1289 if rBandLowIdx==ceil(BandLowIdx)
1290 rBandLowIdx =floor(BandLowIdx);
1291 else
1292 rBandLowIdx =ceil(BandLowIdx);
1293 end
1294 rBandLow =rBandLowIdx /paddedLength /handles.ALFF.SamplePeriod;
1295 if rBandHighIdx==ceil(BandHighIdx)
1296 rBandHighIdx =floor(BandHighIdx);
1297 else
1298 rBandHighIdx =ceil(BandHighIdx);
1299 end
1300 rBandHigh =rBandHighIdx /paddedLength /handles.ALFF.SamplePeriod;
1301 theAnother2Point =sprintf('%gHz --> Index=%g, %gHz --> Index=%g', ...
1302 rBandLow, rBandLowIdx, ...
1303 rBandHigh, rBandHighIdx);
1304
1305 msgbox( sprintf('The Band you want to use is:\n%s\n\nAdopted ALFF Band is:\n%s\n\n\nAnother 2 points'' Infomation:\n%s\n\nYou can view full information in "Power Spectrum"', theWantBandInfo, theRealBandInfo, theAnother2Point), ...
1306 'Calculated Band Range Hint' ,'help');
1307
1308 function BandPass(hObject, handles)
1309 for x=1:size(handles.Cfg.DataDirs, 1)
1310
1311 set(handles.listDataDirs, 'Value', x);
1312 drawnow;
1313 if size(handles.Cfg.DataDirs, 1)>1,
1314 rest_waitbar((x-1)/size(handles.Cfg.DataDirs, 1)+0.01, ...
1315 handles.Cfg.DataDirs{x, 1}, ...
1316 'Band Pass filter','Parent');
1317 end
1318
1319 rest_bandpass(handles.Cfg.DataDirs{x, 1}, ...
1320 handles.Filter.SamplePeriod, ...
1321 handles.Filter.BandHigh, ...
1322 handles.Filter.BandLow, ...
1323 handles.Filter.Retrend, ...
1324 handles.Cfg.MaskFile);
1325
1326 thePostfix ='_filtered';
1327
1328 handles.Cfg.DataDirs{x, 1}=[handles.Cfg.DataDirs{x, 1} , thePostfix];
1329 guidata(hObject, handles);
1330 end
1331 UpdateDisplay(handles);
1332
1333 function btnHelp_Callback(hObject, eventdata, handles)
1334 web('http://resting-fmri.sourceforge.net');
1335
1336