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