⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reho_gui.m

📁 While resting-state fMRI is drawing more and more attention, there has not been a software for its d
💻 M
📖 第 1 页 / 共 4 页
字号:
		'Style', 'edit', ...
		'Units', 'pixels', ...
		'Position', [94 491 50 22], ...
		'BackgroundColor', [1 1 1], ...
		'String', '0.01', ...
		'Enable', 'off');

	set(handles.edtBandHigh,	...
		'Style', 'edit', ...
		'Units', 'pixels', ...
		'Position', [171 491 50 22], ...
		'BackgroundColor', [1 1 1], ...
		'String', '0.08', ...
		'Enable', 'off');

	set(handles.edtSamplePeriod,	...
		'Style', 'edit', ...
		'Units', 'pixels', ...
		'Position', [276 491 50 22], ...
		'BackgroundColor', [1 1 1], ...
		'String', '2', ...
		'Enable', 'off');

	% --- LISTBOXES -------------------------------------
	set(handles.listDataDirs,	...
		'Style', 'listbox', ...
		'Units', 'pixels', ...
		'Position', [14 363 413 98], ...
		'BackgroundColor', [1 1 1], ...
		'String', '');

	%20071103, Add context menu to Input Data Directories to add、delete、export、import……
	handles.hContextMenu =uicontextmenu;
	set(handles.listDataDirs, 'UIContextMenu', handles.hContextMenu);	
	uimenu(handles.hContextMenu, 'Label', 'Add a directory', 'Callback', get(handles.btnSelectDataDir, 'Callback'));	
	uimenu(handles.hContextMenu, 'Label', 'Remove selected directory', 'Callback', 'reho_gui(''DeleteSelectedDataDir'',gcbo,[], guidata(gcbo))');
	uimenu(handles.hContextMenu, 'Label', 'Add recursively all sub-folders of a directory', 'Callback', 'reho_gui(''RecursiveAddDataDir'',gcbo,[], guidata(gcbo))');
	uimenu(handles.hContextMenu, 'Label', '=============================');	
	uimenu(handles.hContextMenu, 'Label', 'Clear all data directories', 'Callback', 'reho_gui(''ClearDataDirectories'',gcbo,[], guidata(gcbo))');
	
		
	% Save handles structure
	guidata(hObject,handles);

%% Log options to a log file for further investigation, 20070507
function Log2File(handles)
	constLineSep= '-------------------------------------------------------------------------------';
	[theVer, theRelease] =rest_misc( 'GetRestVersion');
	theMsgVersion = sprintf('REST Version:%s, Release %s\r\n%s\r\n', theVer, theRelease, constLineSep);	
	theMsgHead = sprintf('ReHo computation log %s\r\n%s\r\n', rest_misc( 'GetDateTimeStr'), constLineSep);
	theMsg =sprintf('%s\r\n%s\r\n\r\n%s', theMsgVersion, theMsgHead, constLineSep);
	theMsg =sprintf('%s\r\nRemove Linear Trend options:\r\n%s\r\n\r\n%s',theMsg,...
					LogRemoveLinearTrend(handles), constLineSep);
	theMsg =sprintf('%s\r\nIdeal Band Pass filter options:\r\n%s\r\n\r\n%s',theMsg,...
					LogBandPassFilter(handles), constLineSep);
	theMsg =sprintf('%s\r\nReHo input parameters:\r\n%s\r\n\r\n%s', theMsg, ...
					LogReHoInputParameters(handles), constLineSep);
	theMsg =sprintf('%s\r\nReHo output parameters:\r\n%s\r\n\r\n%s', theMsg, ...
					LogReHoOutputParameters(handles), constLineSep);
	
	fid = fopen(handles.Log.Filename,'w');
	if fid~=-1
		fprintf(fid,'%s',theMsg);
		fclose(fid);
	else
		errordlg(sprintf('Error to open log file:\n\n%s', handles.Log.Filename));
	end


	
%Log the total elapsed time by once "Do all"
function LogPerformance(handles)	
	theMsg =sprintf('\r\n\r\nTotal elapsed time for Regional Homogeneity Computing: %g  seconds\r\n',handles.Performance);
	fid = fopen(handles.Log.Filename,'r+');
	fseek(fid, 0, 'eof');
	if fid~=-1
		fprintf(fid,'%s',theMsg);
		fclose(fid);
	else
		errordlg(sprintf('Error to open log file:\n\n%s', handles.Log.Filename));
	end

	
function ResultLogString=LogRemoveLinearTrend(handles)
	ResultLogString ='';
	ResultLogString =sprintf('%s\tremove linear trend BEFORE filter: %s\r\n',ResultLogString, handles.Detrend.BeforeFilter);
	%ResultLogString =sprintf('%s\tremove linear trend AFTER filter: %s\r\n',ResultLogString, handles.Detrend.AfterFilter);
	
function ResultLogString=LogBandPassFilter(handles)
	ResultLogString ='';		
	ResultLogString =sprintf('%s\tUse Filter: %s\r\n',ResultLogString, handles.Filter.UseFilter);
	ResultLogString =sprintf('%s\tBand Low: %g\r\n', ResultLogString, handles.Filter.BandLow);
	ResultLogString =sprintf('%s\tBand High: %g\r\n',ResultLogString, handles.Filter.BandHigh);
	ResultLogString =sprintf('%s\tSample Period(i.e. TR): %g\r\n',ResultLogString, handles.Filter.SamplePeriod);
	
function ResultLogString=LogReHoInputParameters(handles)
	ResultLogString ='';
	constLineSep= '-------------------------------------------------------------------------------';
	theDataDirString= '';
	theDataDirCells =get(handles.listDataDirs, 'string');
	for x=1:length(theDataDirCells)
		theDataDirString =sprintf('%s\r\n\t%s', theDataDirString, theDataDirCells{x});
	end
	theDirType ='';
	if strcmpi(handles.Detrend.BeforeFilter, 'Yes')
		theDirType =sprintf(' %s after Detrend processing', theDirType);
	end
	if strcmpi(handles.Detrend.BeforeFilter, 'Yes') && ...
		strcmpi(handles.Filter.UseFilter, 'Yes'),
		theDirType =sprintf(' %s and ', theDirType);
	end
	if strcmpi(handles.Filter.UseFilter, 'Yes')
		theDirType =sprintf(' %s after Filter processing', theDirType);
	end
	ResultLogString =sprintf('%s\tInput Data Directories( %s): \r\n\t%s%s\r\n\t%s\r\n',ResultLogString,...
							theDirType, ...
							constLineSep, ...
							theDataDirString, ...
							constLineSep);
	ResultLogString =sprintf('%s\tMask file: %s\r\n', ResultLogString, handles.Cfg.MaskFile);
	ResultLogString =sprintf('%s\tCluster Count: %g\r\n',ResultLogString, handles.Cfg.ClusterCount);	
		
function ResultLogString=LogReHoOutputParameters(handles)
	ResultLogString ='';
	ResultLogString =sprintf('%s\tPrefix to the Data directories: %s\r\n',ResultLogString, get(handles.edtPrefix, 'String'));
	ResultLogString =sprintf('\tOutput Prefix: %s\r\n', get(handles.edtPrefix, 'String'));
	ResultLogString =sprintf('%s\tOutput Data Directories: %s\r\n',ResultLogString, handles.Cfg.OutputDir);
	ResultLogString =sprintf('%s\tWant mean ReHo map computation: %s \r\n',ResultLogString, handles.Cfg.WantMeanRehoMap);
	

	
	
%compose the log filename	
function ResultLogFileName=GetLogFilename(ALogDirectory, APrefix)
	if isempty(ALogDirectory)
		[pathstr, name, ext, versn] = fileparts(mfilename('fullpath'));	
		ALogDirectory =pathstr;
	end
	if ~strcmp(ALogDirectory(end), filesep)
		ALogDirectory =[ALogDirectory filesep];
	end
	ResultLogFileName=sprintf('%s%s_%sReHo.log', ...
		ALogDirectory, ...
		APrefix, ...
		rest_misc( 'GetDateTimeStr'));


function btnSliceViewer_Callback(hObject, eventdata, handles)
%Display a brain image like MRIcro
	theOldColor=get(hObject,'BackgroundColor');		
	set(hObject,'Enable','off', 'BackgroundColor', 'red');
	drawnow;
	try
		rest_sliceviewer;
		% [filename, pathname] = uigetfile({'*.img', 'ANALYZE files (*.img)'}, ...
														% 'Pick one brain map');
		% if any(filename~=0) && ischar(filename) && length(filename)>4 ,	% not canceled and legal			
			% if ~strcmpi(pathname(end), filesep)%revise pathname to add \ or /
				% pathname = [pathname filesep];
			% end
			% theBrainMap =[pathname filename];
			% rest_sliceviewer('ShowImage', theBrainMap);
		% end
	catch
		rest_misc( 'DisplayLastException');
	end	
	set(hObject,'Enable','on', 'BackgroundColor', theOldColor);
	drawnow;


function btnWaveGraph_Callback(hObject, eventdata, handles)
	%Display a brain image like MRIcro, and show specific voxel's time course and its freq domain's fluctuation
	theOldColor=get(hObject,'BackgroundColor');		
	set(hObject,'Enable','off', 'BackgroundColor', 'red');
	drawnow;
	try
		% if strcmpi(handles.Filter.UseFilter, 'Yes'),
		% else
			% msgbox(sprintf('You didn''t select option "Band Pass" before show Wave Graph. \n\nYou may enable it first and then you can set Band parameter and TR.'));
		% end
		[filename, pathname] = uigetfile({'*.img', 'ANALYZE files (*.img)'}, ...
														'Pick one functional EPI brain map in the dataset''s directory');
		if any(filename~=0) && ischar(filename) && length(filename)>4 ,	% not canceled and legal			
			if ~strcmpi(pathname(end), filesep)%revise pathname to remove extension		
				pathname = [pathname filesep];
			end
			theBrainMap 	=[pathname filename];			
			theViewer =rest_sliceviewer('ShowImage', theBrainMap);
			
			%Set the ALFF figure to show corresponding voxel's time-course and its freq amplitude
			theDataSetDir 	=pathname;
			theVoxelPosition=rest_sliceviewer('GetPosition', theViewer);
			theSamplePeriod =handles.Filter.SamplePeriod;
			theBandRange	=[handles.Filter.BandLow, handles.Filter.BandHigh];						
			rest_powerspectrum('ShowFluctuation', theDataSetDir, theVoxelPosition, ...
							theSamplePeriod, theBandRange);
							
			%Update the Callback
			theCallback 	='';
			cmdDataSetDir	=sprintf('theDataSetDir= ''%s'';', theDataSetDir);
			cmdBrainMap 	=sprintf('theVoxelPosition=rest_sliceviewer(''GetPosition'', %g);', theViewer);
			cmdSamplePeriod =sprintf('theSamplePeriod= %g;', handles.Filter.SamplePeriod);
			cmdBandRange	=sprintf('theBandRange= [%g, %g];', handles.Filter.BandLow, handles.Filter.BandHigh);
			cmdUpdateWaveGraph	='rest_powerspectrum(''ShowFluctuation'', theDataSetDir, theVoxelPosition, theSamplePeriod, theBandRange);';
			theCallback	=sprintf('%s\n%s\n%s\n%s\n%s\n',cmdDataSetDir, ...
								cmdBrainMap, cmdSamplePeriod, cmdBandRange, ...
								cmdUpdateWaveGraph);
			cmdClearVar ='clear theDataSetDir theVoxelPosition theSamplePeriod theBandRange;';
			rest_sliceviewer('UpdateCallback', theViewer, [theCallback cmdClearVar], 'ALFF Analysis');
			
			% Update some Message
			theMsg =sprintf('TR( s): %g\nBand( Hz): %g~%g', ...
							theSamplePeriod, theBandRange(1), theBandRange(2) );
			rest_sliceviewer('SetMessage', theViewer, theMsg);				
		end		
	catch
		rest_misc( 'DisplayLastException');
	end	
	set(hObject,'Enable','on', 'BackgroundColor', theOldColor);
	drawnow;
	rest_waitbar;


function ckboxRemoveTrendBefore_Callback(hObject, eventdata, handles)
	if get(hObject,'Value')
		handles.Detrend.BeforeFilter ='Yes';
	else	
		handles.Detrend.BeforeFilter ='No';
	end	
	guidata(hObject, handles);
	UpdateDisplay(handles);

function ckboxRemoveTrendAfter_Callback(hObject, eventdata, handles)
	if get(hObject,'Value')
		handles.Detrend.AfterFilter ='Yes';
	else	
		handles.Detrend.AfterFilter ='No';
	end	
	guidata(hObject, handles);
	UpdateDisplay(handles);


% --- Executes on button press in btnDetrend.
function btnDetrend_Callback(hObject, eventdata, handles)
	theOldColor=get(hObject,'BackgroundColor');		
	set(hObject,'Enable','off', 'BackgroundColor', 'red');
	drawnow;
	try
		Detrend(hObject,handles);
		msgbox('Remove the Linear Trend Over.',...
				'Detrend successfully' ,'help');
	catch
		rest_misc( 'DisplayLastException');
	end
	rest_waitbar;	
	set(hObject,'Enable','on', 'BackgroundColor', theOldColor);
	drawnow;
	
function Detrend(hObject,handles)
	for x=1:size(handles.Cfg.DataDirs, 1)	
		%Update display
		set(handles.listDataDirs, 'Value', x);
		drawnow;
		if size(handles.Cfg.DataDirs, 1)>1,
			rest_waitbar((x-1)/size(handles.Cfg.DataDirs, 1)+0.01, ...
					handles.Cfg.DataDirs{x, 1}, ...
					'Removing the Linear Trend','Parent');
		end
		
		rest_detrend(handles.Cfg.DataDirs{x, 1}, '_detrend');
		
		%Revise the data directories
		handles.Cfg.DataDirs{x, 1}=[handles.Cfg.DataDirs{x, 1} , '_detrend'];
		guidata(hObject, handles);	% Save Dir names
	end	
	UpdateDisplay(handles);

function BandPass(hObject, handles)
	for x=1:size(handles.Cfg.DataDirs, 1)	
		%Update display
		set(handles.listDataDirs, 'Value', x);
		drawnow;
		if size(handles.Cfg.DataDirs, 1)>1,
			rest_waitbar((x-1)/size(handles.Cfg.DataDirs, 1)+0.01, ...
					handles.Cfg.DataDirs{x, 1}, ...
					'Band Pass filter','Parent');
		end
				
		rest_bandpass(handles.Cfg.DataDirs{x, 1}, ...
					  handles.Filter.SamplePeriod, ...								  
					  handles.Filter.BandHigh, ...
					  handles.Filter.BandLow, ...
					  handles.Filter.Retrend, ...
					  handles.Cfg.MaskFile);
		%build the postfix for filtering
		thePostfix ='_filtered';					
		%Revise the data directories
		handles.Cfg.DataDirs{x, 1}=[handles.Cfg.DataDirs{x, 1} , thePostfix];
		guidata(hObject, handles);	% Save Dir names
	end
	UpdateDisplay(handles);

function btnHelp_Callback(hObject, eventdata, handles)
	web('http://resting-fmri.sourceforge.net');
	%web (sprintf('%s/man/English/ReHo/index.html', rest_misc( 'WhereIsREST')), '-helpbrowser');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -