Home > rest_20090422 > rest_SetROI.m

rest_SetROI

PURPOSE ^

Define ROI wizard by Xiao-Wei Song

SYNOPSIS ^

function varargout=rest_SetROI(AOperation, varargin)

DESCRIPTION ^

Define ROI wizard by Xiao-Wei Song
------------------------------------------------------------------------------------------------------------------------------
    Copyright(c) 2007~2010
    State Key Laboratory of Cognitive Neuroscience and Learning in Beijing Normal University
    Written by Xiao-Wei Song 
    http://resting-fmri.sourceforge.net
------------------------------------------------------------------------------------------------------------------------------
 20070923
     <a href="Dawnwei.Song@gmail.com">Mail to Author</a>: Xiaowei Song
    Version=1.2;
    Release=20081223;
   Modified by Yan Chao-Gan 080808: also support NIFTI images.
   Last Modified by Yan Chao-Gan 081223: use the NIFTI templates.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

DOWNLOAD ^

rest_SetROI.m

SOURCE CODE ^

0001 function varargout=rest_SetROI(AOperation, varargin)    
0002 %Define ROI wizard by Xiao-Wei Song
0003 %------------------------------------------------------------------------------------------------------------------------------
0004 %    Copyright(c) 2007~2010
0005 %    State Key Laboratory of Cognitive Neuroscience and Learning in Beijing Normal University
0006 %    Written by Xiao-Wei Song
0007 %    http://resting-fmri.sourceforge.net
0008 %------------------------------------------------------------------------------------------------------------------------------
0009 % 20070923
0010 %     <a href="Dawnwei.Song@gmail.com">Mail to Author</a>: Xiaowei Song
0011 %    Version=1.2;
0012 %    Release=20081223;
0013 %   Modified by Yan Chao-Gan 080808: also support NIFTI images.
0014 %   Last Modified by Yan Chao-Gan 081223: use the NIFTI templates.
0015 
0016 %Initializitation
0017 persistent REST_SetROI_Cfg; % run-time persistent config
0018 % if ~mislocked(mfilename),mlock; end
0019 
0020 if nargin<1, AOperation='Init'; varargin{1}='';end    %Revise the Start
0021 switch upper(AOperation),
0022 case 'INIT',         %Init
0023     REST_SetROI_Cfg =InitControls(REST_SetROI_Cfg);
0024     if nargin>1,
0025         AROIDefinition =varargin{1};
0026     else
0027         AROIDefinition ='';
0028     end
0029     REST_SetROI_Cfg.ROIDefinition =AROIDefinition;
0030     
0031     if rest_SetROI( 'IsSphereROI' , AROIDefinition),
0032         set(REST_SetROI_Cfg.hSlectSphere, 'Value', 1);
0033         set(REST_SetROI_Cfg.hSlectNonSphere, 'Value', 0);
0034         set(REST_SetROI_Cfg.hSlectTxt, 'Value', 0);
0035     elseif rest_SetROI( 'IsImgROI' , AROIDefinition),
0036         set(REST_SetROI_Cfg.hSlectSphere, 'Value', 0);
0037         set(REST_SetROI_Cfg.hSlectNonSphere, 'Value', 1);
0038         set(REST_SetROI_Cfg.hSlectTxt, 'Value', 0);
0039     elseif rest_SetROI( 'IsTxtROI' , AROIDefinition),
0040         set(REST_SetROI_Cfg.hSlectSphere, 'Value', 0);
0041         set(REST_SetROI_Cfg.hSlectNonSphere, 'Value', 0);
0042         set(REST_SetROI_Cfg.hSlectTxt, 'Value', 1);
0043     else
0044         %error or  the definition is space/NaN ...
0045     end
0046     rest_SetROI( 'UpdateDisplay' );
0047 
0048     uiwait(REST_SetROI_Cfg.hFig);
0049     varargout{1} =REST_SetROI_Cfg.ROIDefinition;
0050 
0051 case 'DELETE',         %Delete
0052     if nargin~=1, error('Usage: result =rest_SetROI( ''Delete'');'); end    
0053     uiresume(REST_SetROI_Cfg.hFig);
0054     delete(REST_SetROI_Cfg.hFig);
0055 
0056 case 'ISSPHEREROI',        %IsSphereROI
0057     if nargin~=2, error('Usage: result =rest_SetROI( ''IsSphereROI'' , AROIDefinition);'); end    
0058     AROIDefinition =varargin{1};
0059     if rest_SphereROI( 'IsBallDefinition', AROIDefinition),
0060         varargout{1}=1;
0061     else
0062         varargout{1}=0;
0063     end
0064     
0065 case {'ISIMGROI', 'ISTMAPROI','ISTEMPLATEROI', 'ISUSERROI'}        %IsImgROI    %IsTMapROI     %IsTemplateROI     %IsUserROI
0066     if nargin~=2, error('Usage: result =rest_SetROI( ''IsImgROI'' , AROIDefinition);'); end    
0067     AROIDefinition =varargin{1};
0068     varargout{1}=0;
0069     if 2==exist(AROIDefinition, 'file'),
0070         [pathstr, name, ext, versn] = fileparts(AROIDefinition);
0071         if strcmpi(ext, '.img'),
0072             varargout{1}=1;        
0073         end    
0074     end
0075     
0076 case 'ISTXTROI',        %IsTxtROI
0077     if nargin~=2, error('Usage: result =rest_SetROI( ''IsTxtROI'' , AROIDefinition);'); end    
0078     AROIDefinition =varargin{1};
0079     varargout{1}=0;
0080     if 2==exist(AROIDefinition, 'file'),
0081         [pathstr, name, ext, versn] = fileparts(AROIDefinition);
0082         if strcmpi(ext, '.txt'),
0083             varargout{1}=1;        
0084         end    
0085     end
0086     
0087 case 'UPDATEDISPLAY',        %UpdateDisplay
0088     if nargin~=1, error('Usage: result =rest_SetROI( ''UpdateDisplay'' );'); end    
0089     UpdateDisplay(REST_SetROI_Cfg);
0090     
0091 case 'SELECT',        %Select
0092     if nargin~=1, error('Usage: result =rest_SetROI( ''Select'' );'); end
0093     theObj    =get(REST_SetROI_Cfg.hFig, 'CurrentObject');
0094     %Check whether the previous selected object is Sphere
0095     if ( get(REST_SetROI_Cfg.hSlectSphere, 'Value') && theObj~=REST_SetROI_Cfg.hSlectSphere ) ... 
0096         || (get(REST_SetROI_Cfg.hSlectNonSphere, 'Value') && theObj~=REST_SetROI_Cfg.hSlectNonSphere ) ...
0097         || (get(REST_SetROI_Cfg.hSlectTxt, 'Value') && theObj~=REST_SetROI_Cfg.hSlectTxt ),
0098         %Clear the Sphere definition defined in other way
0099         REST_SetROI_Cfg.ROIDefinition ='';    
0100     end    
0101     theRadioButtons =findobj(REST_SetROI_Cfg.hFig, 'Style', 'radiobutton');
0102     for x=1:length(theRadioButtons), 
0103         set(theRadioButtons(x), 'Value', 0);
0104     end
0105     set(theObj, 'Value', 1);
0106     if theObj ~= REST_SetROI_Cfg.hSlectSphere && theObj ~= REST_SetROI_Cfg.hSlectTxt,
0107         set(REST_SetROI_Cfg.hSlectNonSphere, 'Value', 1);
0108     end
0109     UpdateDisplay(REST_SetROI_Cfg);
0110     
0111 case 'NEXT',        %Next
0112     if nargin~=1, error('Usage: result =rest_SetROI( ''Next'' );'); end
0113     set(REST_SetROI_Cfg.hNext, 'Enable', 'off', 'ForegroundColor', 'red');
0114     try
0115         if get(REST_SetROI_Cfg.hSlectSphere, 'Value'),
0116             REST_SetROI_Cfg.ROIDefinition =rest_SphereROI('Init', REST_SetROI_Cfg.ROIDefinition);
0117         elseif get(REST_SetROI_Cfg.hSlectNonSphere, 'Value'),            
0118             isNeedDefineCluster =true;
0119             if get(REST_SetROI_Cfg.hFromTMap, 'Value'),
0120                 [filename, pathname] = uigetfile({'*.img', 'ANALYZE or NIFTI files (*.img)'},'Pick the  statistical t-map');    
0121             elseif get(REST_SetROI_Cfg.hFromAAL, 'Value'),    
0122                 pathname =fullfile(rest_misc( 'WhereIsREST'),'Template');
0123                 filename ='aal.nii'; %Yan Chao-Gan 081223: use the NIFTI templates.
0124             elseif get(REST_SetROI_Cfg.hFromBrodmann, 'Value'),
0125                 pathname =fullfile(rest_misc( 'WhereIsREST'),'Template');
0126                 filename ='brodmann.nii'; %Yan Chao-Gan 081223: use the NIFTI templates.
0127             elseif get(REST_SetROI_Cfg.hFromUserDefinedMask, 'Value'),
0128                 [filename, pathname] = uigetfile({'*.img', 'ANALYZE or NIFTI files (*.img)'},'Pick the user defined mask file(ANALYZE or NIFTI FORMAT)');
0129                 REST_SetROI_Cfg.ROIDefinition =fullfile(pathname, filename);
0130                 isNeedDefineCluster =false;
0131             else
0132                 warndlg('You must select one option');
0133             end
0134             
0135             if isNeedDefineCluster && any(filename~=0) && ischar(filename),    % not canceled and legal
0136                 theFig =rest_sliceviewer('ShowOverlay', fullfile(pathname, filename));
0137                 theCallback =sprintf(['uiresume(%f);'], theFig);
0138                 rest_sliceviewer('UpdateCallback_Save2Mask', theFig, theCallback);
0139                 set(theFig, 'WindowStyle', 'modal');
0140                 uiwait(theFig);
0141                 REST_SetROI_Cfg.ROIDefinition =rest_sliceviewer('GetSavedMaskFilename', theFig);
0142                 rest_sliceviewer('Delete', theFig);
0143             end
0144         elseif get(REST_SetROI_Cfg.hSlectTxt, 'Value'),            
0145             [filename, pathname] = uigetfile({'*.txt', 'User defined time courses (*.txt)'},'Pick the user defined txt file(One column is a time course)');
0146             REST_SetROI_Cfg.ROIDefinition =fullfile(pathname, filename);            
0147         end
0148     catch
0149         rest_misc('DisplayLastException');
0150     end
0151     UpdateDisplay(REST_SetROI_Cfg);
0152     
0153 case 'UPDATEROIDEFINITION',            %UpdateROIDefinition
0154     if nargin~=2, error('Usage: result =rest_SetROI( ''UpdateROIDefinition'' , AROIDefinition);'); end    
0155     REST_SetROI_Cfg.ROIDefinition =varargin{1};
0156     
0157 case 'MANUALYCHANGEROIDEFINITIONINEDIT',        %ManualyChangeROIDefinitionInEdit
0158     if nargin~=1, error('Usage: result =rest_SetROI( ''ManualyChangeROIDefinitionInEdit'');'); end    
0159     REST_SetROI_Cfg.ROIDefinition =get(gcbo, 'String');
0160     
0161 case 'VIEWROI',        %ViewROI
0162     if nargin~=1, error('Usage: rest_SetROI( ''ViewROI'');'); end
0163     if isempty(REST_SetROI_Cfg.ROIDefinition) || all(isspace(REST_SetROI_Cfg.ROIDefinition)),
0164         warndlg('No ROI defined yet!');
0165     else
0166         rest_misc( 'ViewROI', REST_SetROI_Cfg.ROIDefinition); 
0167     end
0168     
0169 otherwise,
0170     
0171 end
0172 
0173 function Result =InitControls(AConfig)
0174     theFig =figure('Units', 'pixel', 'Toolbar', 'none', 'MenuBar', 'none', ...
0175                 'CloseRequestFcn', sprintf('rest_SetROI(''Delete'');'), ...
0176                 'Resize', 'off', ...
0177                 'NumberTitle', 'off', 'Name', 'ROI (Region of interest) Definition');
0178     thePos =get(theFig, 'Position');
0179     set(theFig, 'Position', [thePos(1) thePos(2) 400 400],'WindowStyle', 'modal');
0180     movegui(theFig, 'center');
0181     set(theFig, 'DeleteFcn', sprintf('rest_SetROI(''Delete'');')  );
0182     AConfig.hFig =theFig;
0183     
0184     MarginX =10; MarginY =10;
0185     OffsetX =MarginX;
0186     OffsetY =MarginY +25 +MarginY;    
0187     theLeft =OffsetX; theBottom =OffsetY;
0188     
0189     %Time Course
0190     uicontrol(AConfig.hFig, 'Style','Frame', 'Units','pixels', ...
0191             'BackgroundColor', get(AConfig.hFig,'Color'), ...
0192             'Position', [theLeft,theBottom,380,70]);
0193     hSlectTxt =uicontrol('Style', 'radiobutton',    'Units', 'pixels', ...
0194                 'BackgroundColor', get(AConfig.hFig,'Color'), 'Value', 0,...
0195                 'Position', [theLeft+10,theBottom+60,120,20],...
0196                 'String', 'Time courses');
0197     uicontrol('Style', 'text',    'Units', 'pixels', ...
0198             'BackgroundColor', get(AConfig.hFig,'Color'), ...
0199             'HorizontalAlignment', 'left', ...
0200             'Visible', 'on', ...
0201             'Position', [theLeft+10,theBottom+30,360,25], ...
0202             'String', sprintf(['User defined time courses contained in a txt file']));
0203     hROITxtLocation =uicontrol('Style', 'edit', 'Units', 'pixels', ...%'BackgroundColor', get(AConfig.hFig,'Color'), ...
0204                     'HorizontalAlignment', 'left', ...
0205                     'Visible', 'on', ...                    
0206                     'ForegroundColor', 'red', 'FontWeight', 'bold', ...
0207                     'Position', [theLeft+10,theBottom+10,360,20], ...
0208                     'String', 'dd');
0209     set(hROITxtLocation, 'Callback',sprintf('rest_SetROI( ''ManualyChangeROIDefinitionInEdit'')'));
0210     
0211     %ROI
0212     OffsetX =MarginX;
0213     OffsetY =MarginY+80;    
0214     
0215     theLeft =OffsetX; theBottom =OffsetY +40;
0216     uicontrol(AConfig.hFig, 'Style','Frame', 'Units','pixels', ...
0217             'BackgroundColor', get(AConfig.hFig,'Color'), ...
0218             'Position', [theLeft,theBottom,380,160]);
0219     hSlectNonSphere =uicontrol('Style', 'radiobutton',    'Units', 'pixels', ...
0220                 'BackgroundColor', get(AConfig.hFig,'Color'), ...
0221                 'Position', [theLeft+10,theBottom+150,120,20],'String', 'ROI');
0222     hNonSphereDescription =uicontrol('Style', 'text',    'Units', 'pixels', ...
0223                 'BackgroundColor', get(AConfig.hFig,'Color'), ...
0224                 'HorizontalAlignment', 'left', ...
0225                 'Visible', 'on', ...
0226                 'Position', [theLeft+10,theBottom+40,360,105], ...
0227                 'String', sprintf(['There are 4 methods to generate the ROI mask file:' ...
0228                  '\n\n1. From statistical t-map by selecting cluster after thresholding' ...
0229                   '\n2. From AAL template by selecting specific area'...
0230                   '\n3. From Brodmann template by selecting specific area'...
0231                   '\n4. From user defined mask file']));
0232     hFromTMap=uicontrol('Style', 'radiobutton',    'Units', 'pixels', ...
0233                 'BackgroundColor', get(AConfig.hFig,'Color'), ...
0234                 'Visible', 'off', ...
0235                 'Position', [theLeft+30,theBottom+105,340,16],'String', '1. From statistical t-map by selecting cluster after thresholding');
0236     hFromAAL=uicontrol('Style', 'radiobutton',    'Units', 'pixels', ...
0237                 'BackgroundColor', get(AConfig.hFig,'Color'), ...
0238                 'Visible', 'off', ...
0239                 'Position', [theLeft+30,theBottom+85,340,16],'String', '2. From AAL template by selecting specific area');
0240     hFromBrodmann=uicontrol('Style', 'radiobutton',    'Units', 'pixels', ...
0241                 'BackgroundColor', get(AConfig.hFig,'Color'), ...
0242                 'Visible', 'off', ...
0243                 'Position', [theLeft+30,theBottom+65,340,16],'String', '3. From Brodmann template by selecting specific area');
0244     hFromUserDefinedMask=uicontrol('Style', 'radiobutton',    'Units', 'pixels', ...
0245                 'BackgroundColor', get(AConfig.hFig,'Color'), ...
0246                 'Visible', 'off', ...
0247                 'Position', [theLeft+30,theBottom+45,340,16],'String', '4. From user defined mask file');
0248     hROINonSphereInfo =uicontrol('Style', 'edit', 'Units', 'pixels', ...%'BackgroundColor', get(AConfig.hFig,'Color'), ...
0249                     'HorizontalAlignment', 'left', ...
0250                     'Visible', 'on', ...
0251                     'ForegroundColor', 'red', 'FontWeight', 'bold', ...
0252                     'Position', [theLeft+10,theBottom+10,360,20], ...
0253                     'String', 'dd');
0254     set(hROINonSphereInfo, 'Callback',sprintf('rest_SetROI( ''ManualyChangeROIDefinitionInEdit'')'));
0255     
0256     
0257     %Seed ROI
0258     theLeft =OffsetX; theBottom =OffsetY +220;
0259     uicontrol(AConfig.hFig, 'Style','Frame', 'Units','pixels', ...
0260             'BackgroundColor', get(AConfig.hFig,'Color'), ...
0261             'Position', [theLeft,theBottom,380,70]);
0262     hSlectSphere =uicontrol('Style', 'radiobutton',    'Units', 'pixels', ...
0263                 'BackgroundColor', get(AConfig.hFig,'Color'), 'Value', 1,...
0264                 'Position', [theLeft+10,theBottom+60,120,20],'String', 'Seed ROI');
0265     uicontrol('Style', 'text',    'Units', 'pixels', ...
0266             'BackgroundColor', get(AConfig.hFig,'Color'), ...
0267             'HorizontalAlignment', 'left', ...
0268             'Visible', 'on', ...
0269             'Position', [theLeft+10,theBottom+30,360,25], ...
0270             'String', sprintf(['Define a seed ROI by setting the center coordinate and the radius(mm)']));
0271     hROISphereInfo =uicontrol('Style', 'edit', 'Units', 'pixels', ...%'BackgroundColor', get(AConfig.hFig,'Color'), ...
0272                     'HorizontalAlignment', 'left', ...
0273                     'Visible', 'on', ...
0274                     'ForegroundColor', 'red', 'FontWeight', 'bold', ...
0275                     'Position', [theLeft+10,theBottom+10,360,20], ...
0276                     'String', 'dd');
0277     set(hROISphereInfo, 'Callback',sprintf('rest_SetROI( ''ManualyChangeROIDefinitionInEdit'')'));
0278     
0279     
0280     uicontrol('Style', 'pushbutton',    'Units', 'pixels', ...
0281                 'Visible', 'on', 'Callback', sprintf('rest_SetROI(''Delete'');') ,...
0282                 'Position', [MarginX,MarginY,75,25], ...
0283                 'String', 'Done');
0284     %rest_misc( 'ViewROI', AROIDef);
0285     uicontrol('Style', 'pushbutton',    'Units', 'pixels', ...
0286                 'Visible', 'on', 'Callback', sprintf('rest_SetROI(''ViewROI'');') ,...
0287                 'Position', [MarginX+80,MarginY,75,25], ...
0288                 'String', 'View ROI');
0289     
0290     hNext =uicontrol('Style', 'pushbutton',    'Units', 'pixels', ...
0291                 'Visible', 'on', ...
0292                 'Callback', 'rest_SetROI( ''Next'' );', ...
0293                 'Position', [MarginX+305,MarginY,75,25], ...
0294                 'String', 'Next');
0295     
0296     theRadioButtons =findobj(AConfig.hFig, 'Style', 'radiobutton');
0297     for x=1:length(theRadioButtons), 
0298         set(theRadioButtons(x), 'Callback', 'rest_SetROI( ''Select'' );');
0299     end
0300     %Save handles
0301     AConfig.hSlectNonSphere =hSlectNonSphere;
0302     AConfig.hNonSphereDescription =hNonSphereDescription;    
0303     AConfig.hFromTMap        =hFromTMap    ;    
0304     AConfig.hFromAAL    =hFromAAL;
0305     AConfig.hFromBrodmann    =hFromBrodmann;
0306     AConfig.hFromUserDefinedMask=hFromUserDefinedMask;    
0307     AConfig.hROINonSphereInfo=hROINonSphereInfo;
0308     
0309     AConfig.hSlectSphere=hSlectSphere;
0310     AConfig.hROISphereInfo=hROISphereInfo;
0311     
0312     AConfig.hSlectTxt =hSlectTxt;
0313     AConfig.hROITxtLocation =hROITxtLocation;
0314     
0315     AConfig.hNext =hNext;
0316         
0317     Result =AConfig;
0318     
0319 function UpdateDisplay(AConfig)
0320     if get(AConfig.hSlectSphere, 'Value'),
0321         set(AConfig.hROISphereInfo, 'String', AConfig.ROIDefinition);
0322         
0323         set(AConfig.hSlectNonSphere, 'Value', 0);
0324         set(AConfig.hNonSphereDescription, 'String', sprintf(['There are 4 methods to generate the ROI mask file:' ...
0325                  '\n\n1. From statistical t-map by selecting cluster after thresholding' ...
0326                   '\n2. From AAL template by selecting specific area'...
0327                   '\n3. From Brodmann template by selecting specific area'...
0328                   '\n4. From user defined mask file'])); 
0329         set(AConfig.hFromTMap, 'Visible', 'off');
0330         set(AConfig.hFromAAL, 'Visible', 'off');
0331         set(AConfig.hFromBrodmann, 'Visible', 'off');
0332         set(AConfig.hFromUserDefinedMask, 'Visible', 'off');
0333         set(AConfig.hROINonSphereInfo, 'String', '');
0334                 
0335         set(AConfig.hSlectTxt, 'Value', 0);
0336         set(AConfig.hROITxtLocation, 'String', '');
0337         
0338     elseif get(AConfig.hSlectNonSphere, 'Value'),
0339         set(AConfig.hSlectSphere, 'Value', 0);
0340         set(AConfig.hROISphereInfo, 'String', '');
0341         
0342         set(AConfig.hNonSphereDescription, 'String',sprintf(['There are 4 methods to generate the ROI mask file:'])); 
0343         set(AConfig.hFromTMap, 'Visible', 'on');
0344         set(AConfig.hFromAAL, 'Visible', 'on');
0345         set(AConfig.hFromBrodmann, 'Visible', 'on');
0346         set(AConfig.hFromUserDefinedMask, 'Visible', 'on');
0347         set(AConfig.hROINonSphereInfo, 'String', AConfig.ROIDefinition);
0348         
0349         set(AConfig.hSlectTxt, 'Value', 0);
0350         set(AConfig.hROITxtLocation, 'String', '');
0351     elseif get(AConfig.hSlectTxt, 'Value'),
0352         set(AConfig.hSlectSphere, 'Value', 0);
0353         set(AConfig.hROISphereInfo, 'String', '');    
0354         
0355         set(AConfig.hSlectNonSphere, 'Value', 0);
0356         set(AConfig.hNonSphereDescription, 'String', sprintf(['There are 4 methods to generate the ROI mask file:' ...
0357                  '\n\n1. From statistical t-map by selecting cluster after thresholding' ...
0358                   '\n2. From AAL template by selecting specific area'...
0359                   '\n3. From Brodmann template by selecting specific area'...
0360                   '\n4. From user defined mask file'])); 
0361         set(AConfig.hFromTMap, 'Visible', 'off');
0362         set(AConfig.hFromAAL, 'Visible', 'off');
0363         set(AConfig.hFromBrodmann, 'Visible', 'off');
0364         set(AConfig.hFromUserDefinedMask, 'Visible', 'off');
0365         set(AConfig.hROINonSphereInfo, 'String', '');
0366         
0367         set(AConfig.hROITxtLocation, 'String', AConfig.ROIDefinition);        
0368     end
0369     
0370     set(AConfig.hNext, 'Enable', 'on', 'ForegroundColor', 'black');
0371

Generated on Wed 29-Apr-2009 01:06:38 by m2html © 2005