function xjview(varargin) % xjview, version 4 % % usage 1: xjview (no argument) % for displaying a result img file, or multiple image files, % (which will be loaded later) and changing p-value or t/f-value % usage 2: xjview(imagefilename) % for displaying the result img file and changing p-value or % t-value % Example: xjView spmT_0002.img % xjView('spmT_0002.img') % xjView mymask.img % usage 3: xjview(imagefilename1, imagefilename2, ...) % for displaying the result img files and changing p-value or % t/f-value % Example: xjView spmT_0002.img spmT_0005.img spmT_0007.img % xjView('spmT_0002.img', 'spmT_0003.img', 'spmT_0006.img') % xjView myMask1.img myMask2.img myMask3.img % usage 4: xjview(mnicoord, intensity) % for displaying where are the mni coordinates % mnicoord: Nx3 matrix of mni coordinates % intensity: (optional) Nx1 matrix, usually t values of the % corresponding voxels % Example: xjView([20 10 1; -10 2 5],[1;2]) % xjView([20 10 1; -10 2 5]) % Note: to use xjview this way, you may need to modify the value % of M and DIM in the begining of xjview.m % % http://people.hnl.bcm.tmc.edu/cuixu/xjView % % by Xu Cui and Jian Li 2/21/2005 % last modified: 11/20/2007 (new database, all database from wfu_pickatlas, including aal % last modified: 06/01/2007 (correct FDR corrected p-value list, change intensity to handles.intensity{1}) % last modified: 02/18/2007 (add colorbar max control) % last modified: 11/16/2006 (keyboard shortcut for open image and open roi file) % last modified: 06/16/2006 (spm5 compatible) % last modified: 05/30/2006 (left/right flip, path of mask.img and templateFile.img) % last modified: 05/08/2006 (debug CallBack_volumePush function, change handles.intensity{1} to intensity) % last modified: 04/03/2006 (modify tr) % last modified: 12/28/2005 (modify SPM process) % % Thank Sergey Pakhomov for sharing his database (MNI Space Utility). % Thank Yuval Cohen for the maximize figure function (maximize.m) % warnstate = warning; warning off; % pre-set values % important! you need compare the display of xjview and spm. If you find % xjview flipped the left/right, you need to set leftrightflip = 1; % otherwise leave it to 0. leftrightflip = 0; % You only need to change M and DIM when you want to use xjview under % 'usage 4'. M = ... [-4 0 0 84;... 0 4 0 -116;... 0 0 4 -56;... 0 0 0 1]; DIM = [41 48 35]'; TR = 2; % you don't need to set TR is you only use the viewing part of xjview % system settings try spmdir = spm('dir'); %spm('defaults', 'fmri'); catch disp('Please add spm path.'); warning(warnstate(1).state); return end try spm('defaults', 'fmri'); catch []; end if ispc os = 'windows'; elseif isunix os = 'linux'; else warndlg('I don''t know what kind of computer you are using. I assumed it is unix.', 'What computer are you using?'); os = 'linux'; end screenResolution = get(0,'ScreenSize'); xjviewpath = fileparts(which('xjview')); % pre-set values pValue = 0.001; intensityThreshold = 0; clusterSizeThreshold = 5; % Appearance Settings figurePosition = [0.100, 0.050, 0.660, 0.880]; sectionViewPosition = [0.5,0.61,0.45,0.45]; glassViewAxesPosition = [0.000, 0.600, 0.464, 0.400]; if screenResolution(3) <= 1024 figurePosition = [0.100, 0.050, 0.700, 0.900]; sectionViewPosition = [0.5, 0.61, 0.45, 0.46]; glassViewAxesPosition = [0.000, 0.600, 0.464, 0.400]; end left = 0.01; editBoxHeight = 0.05; editBoxWidth = 0.200; editBoxLeft = 0.100; controlPanelPosition = [left, 0.080, 0.500, 0.500]; stretchMatrix = diag([controlPanelPosition(3),controlPanelPosition(4),controlPanelPosition(3),controlPanelPosition(4)]); controlPanelOffset = controlPanelPosition' .* [1,1,0,0]'; heightUnit = 0.055; sliderPosition = stretchMatrix*[0.000, 0*heightUnit, 1.000, editBoxHeight]' + controlPanelOffset; pValueTextPosition = stretchMatrix*[0.000, 1*heightUnit, editBoxWidth, editBoxHeight]' + controlPanelOffset; pValueEditPosition = stretchMatrix*[0.110, 1*heightUnit, editBoxWidth*4/3, editBoxHeight]' + controlPanelOffset; intensityThresholdTextPosition = stretchMatrix*[0.400, 1*heightUnit, editBoxWidth, editBoxHeight]' + controlPanelOffset; intensityThresholdEditPosition = stretchMatrix*[0.520, 1*heightUnit, editBoxWidth*3/3, editBoxHeight]' + controlPanelOffset; dfTextPosition = stretchMatrix*[0.740, 1*heightUnit, 0.8-0.74, editBoxHeight]' + controlPanelOffset; dfEditPosition = stretchMatrix*[0.800, 1*heightUnit, editBoxWidth, editBoxHeight]' + controlPanelOffset; clusterSizeThresholdTextPosition = stretchMatrix*[0.000, 2*heightUnit, editBoxWidth, editBoxHeight]' + controlPanelOffset; clusterSizeThresholdEditPosition = stretchMatrix*[0.150, 2*heightUnit, editBoxWidth, editBoxHeight]' + controlPanelOffset; pickThisClusterPushPosition = stretchMatrix*[0.400, 2*heightUnit, editBoxWidth*1, editBoxHeight]' + controlPanelOffset; selectThisClusterPushPosition = stretchMatrix*[0.600, 2*heightUnit, editBoxWidth*1, editBoxHeight]' + controlPanelOffset; clearSelectedClusterPushPosition = stretchMatrix*[0.800, 2*heightUnit, editBoxWidth*1, editBoxHeight]' + controlPanelOffset; thisClusterSizeTextPosition = stretchMatrix*[0.600, 2*heightUnit, editBoxWidth, editBoxHeight]' + controlPanelOffset; thisClusterSizeEditPosition = stretchMatrix*[0.800, 2*heightUnit, editBoxWidth, editBoxHeight]' + controlPanelOffset; loadImagePushPosition = stretchMatrix*[0.000, 3*heightUnit, editBoxWidth, editBoxHeight]' + controlPanelOffset; imageFileEditPosition = stretchMatrix*[0.200, 3*heightUnit, 1-editBoxWidth, editBoxHeight]' + controlPanelOffset; saveImagePushPosition = stretchMatrix*[0.000, 4*heightUnit, editBoxWidth, editBoxHeight]' + controlPanelOffset; saveImageFileEditPosition = stretchMatrix*[0.200, 4*heightUnit, 1-editBoxWidth, editBoxHeight]' + controlPanelOffset; saveResultPSPushPosition = stretchMatrix*[0.000, 5*heightUnit, editBoxWidth, editBoxHeight]' + controlPanelOffset; resultPSFileEditPosition = stretchMatrix*[0.200, 5*heightUnit, 1-editBoxWidth, editBoxHeight]' + controlPanelOffset; displayIntensityTextPosition = stretchMatrix*[0.000, 3*heightUnit, editBoxWidth+0.1, editBoxHeight]' + controlPanelOffset; allIntensityRadioPosition = stretchMatrix*[0.250, 3*heightUnit, editBoxWidth, editBoxHeight]' + controlPanelOffset; positiveIntensityRadioPosition = stretchMatrix*[0.400, 3*heightUnit, editBoxWidth, editBoxHeight]' + controlPanelOffset; negativeIntensityRadioPosition = stretchMatrix*[0.550, 3*heightUnit, editBoxWidth, editBoxHeight]' + controlPanelOffset; renderViewCheckPosition = stretchMatrix*[0.780, 3*heightUnit, editBoxWidth, editBoxHeight]' + controlPanelOffset; hideControlPushPosition = stretchMatrix*[0.200, 4*heightUnit, editBoxWidth, editBoxHeight]' + controlPanelOffset; volumePushPosition = stretchMatrix*[0.000, 4*heightUnit, editBoxWidth, editBoxHeight]' + controlPanelOffset; commonRegionPushPosition = stretchMatrix*[0.200, 4*heightUnit, editBoxWidth, editBoxHeight]' + controlPanelOffset; displayPushPosition = stretchMatrix*[0.200, 4*heightUnit, editBoxWidth, editBoxHeight]' + controlPanelOffset; allinonePushPosition = stretchMatrix*[0.400, 4*heightUnit, editBoxWidth, editBoxHeight]' + controlPanelOffset; searchPushPosition = stretchMatrix*[0.000, 6*heightUnit, editBoxWidth, editBoxHeight]' + controlPanelOffset; searchContentEditPosition = stretchMatrix*[0.200, 6*heightUnit, editBoxWidth*2, editBoxHeight]' + controlPanelOffset; searchTextPosition = stretchMatrix*[0.600, 6*heightUnit, editBoxWidth, editBoxHeight]' + controlPanelOffset; searchEnginePopPosition = stretchMatrix*[0.600, 6*heightUnit, 1-0.6, editBoxHeight]' + controlPanelOffset; overlayPushPosition = stretchMatrix*[0.000, 5*heightUnit, editBoxWidth, editBoxHeight]' + controlPanelOffset; overlayEditPosition = stretchMatrix*[0.200, 5*heightUnit, 0.6-editBoxWidth, editBoxHeight]' + controlPanelOffset; overlayPopPosition = stretchMatrix*[0.600, 5*heightUnit, 1-0.6, editBoxHeight]' + controlPanelOffset; helpPosition = stretchMatrix*[0.800, 5*heightUnit, editBoxWidth, editBoxHeight]' + controlPanelOffset; infoTextBoxPosition = stretchMatrix*[0.000, 8*heightUnit, 1, editBoxHeight*9]' + controlPanelOffset; %xjViewPosition = stretchMatrix*[0.400, 13*heightUnit, editBoxWidth*2.5, editBoxHeight*3]' + controlPanelOffset; sectionViewListboxPosition = [sectionViewPosition(1)+0.4, sectionViewPosition(2)+0.02, 0.1, 0.14]; sectionViewMoreTargetPushPosition = [sectionViewListboxPosition(1),sectionViewListboxPosition(2)-0.02,0.10,0.02]; xHairCheckPosition = [sectionViewListboxPosition(1),sectionViewListboxPosition(2)+0.14,0.15,0.02]; setTRangeEditPosition = [sectionViewListboxPosition(1),sectionViewListboxPosition(2)-0.06,0.10,0.02]; setTRangeTextPosition = [sectionViewListboxPosition(1),sectionViewListboxPosition(2)-0.04,0.10,0.02]; getStructurePushPosition = [glassViewAxesPosition(1), glassViewAxesPosition(2)-0.06, editBoxWidth/2, editBoxHeight/2]; structureEditPosition = [getStructurePushPosition(1), getStructurePushPosition(2), 1, getStructurePushPosition(4)]; framePosition = (controlPanelPosition - controlPanelOffset')*1.05 + 0.95*controlPanelOffset'; % draw figure and control figureBKcolor=[176/255 252/255 188/255]; figureBKcolor=get(0,'Defaultuicontrolbackgroundcolor'); f = figure('unit','normalized','position',figurePosition,'Color',figureBKcolor,'defaultuicontrolBackgroundColor', figureBKcolor,... 'Name','xjView', 'NumberTitle','off','resize','off','CloseRequestFcn', {@CallBack_quit, warnstate(1).state}, 'visible','off'); handles = guihandles(f); % databases try X = load('TDdatabase'); handles.DB = X.DB; handles.wholeMaskMNIAll = X.wholeMaskMNIAll; catch errordlg('I can''t find TDdatabase.mat','TDdatabase not found'); end handles.figure = f; handles.frame = uicontrol(handles.figure,'style','frame',... 'unit','normalized',... 'position',framePosition,... 'Visible','off'); handles.slider = uicontrol(handles.figure,'style','slider',... 'unit','normalized',... 'position',sliderPosition,... 'max',1,'min',0,... 'sliderstep',[0.01,0.10],... 'callback',@CallBack_slider,... 'value',0,'Visible','on'); handles.pValueTextPosition = uicontrol(handles.figure,'style','text',... 'unit','normalized','position',pValueTextPosition,... 'string','pValue=','horizontal','left'); handles.pValueEdit = uicontrol(handles.figure,'style','edit',... 'unit','normalized','position',pValueEditPosition,... 'horizontal','left',... 'String', num2str(pValue),... 'BackgroundColor', 'w',... 'callback',@CallBack_pValueEdit); handles.intensityThresholdText = uicontrol(handles.figure,'style','text',... 'unit','normalized','position',intensityThresholdTextPosition,... 'string',' intensity=','horizontal','left'); handles.intensityThresholdEdit = uicontrol(handles.figure,'style','edit',... 'unit','normalized','position',intensityThresholdEditPosition,... 'horizontal','left',... 'BackgroundColor', 'w',... 'String', num2str(intensityThreshold),... 'callback',@CallBack_intensityThresholdEdit); handles.dfText = uicontrol(handles.figure,'style','text',... 'unit','normalized','position',dfTextPosition,... 'string','df= ','horizontal','right'); handles.dfEdit = uicontrol(handles.figure,'style','edit',... 'unit','normalized','position',dfEditPosition,... 'horizontal','left',... 'BackgroundColor', 'w',... 'String', '',... 'callback',@CallBack_dfEdit); handles.clusterSizeThresholdText = uicontrol(handles.figure,'style','text',... 'unit','normalized','position',clusterSizeThresholdTextPosition,... 'string','cluster size >=','horizontal','left'); handles.clusterSizeThresholdEdit = uicontrol(handles.figure,'style','edit',... 'unit','normalized','position',clusterSizeThresholdEditPosition,... 'horizontal','left',... 'BackgroundColor', 'w',... 'String', num2str(clusterSizeThreshold),... 'callback',@CallBack_clusterSizeThresholdEdit); handles.thisClusterSizeText = uicontrol(handles.figure,'style','text',... 'unit','normalized','position',thisClusterSizeTextPosition,... 'string','size= ','horizontal','right', 'visible', 'off'); handles.thisClusterSizeEdit = uicontrol(handles.figure,'style','edit',... 'unit','normalized','position',thisClusterSizeEditPosition,... 'horizontal','left',... 'Enable', 'inactive',... 'String', '','visible','off'); handles.imageFileEdit = uicontrol(handles.figure,'style','edit',... 'unit','normalized','position',imageFileEditPosition,... 'horizontal','left',... 'String', '',... 'BackgroundColor', 'w',... 'callback',@CallBack_imageFileEdit,... 'visible','off'); handles.saveImageFileEdit = uicontrol(handles.figure,'style','edit',... 'unit','normalized','position',saveImageFileEditPosition,... 'horizontal','left',... 'BackgroundColor', 'w',... 'String', 'myMask.img',... 'callback',@CallBack_saveImageFileEdit,... 'visible','off'); handles.saveResultPSEdit = uicontrol(handles.figure,'style','edit',... 'unit','normalized','position',resultPSFileEditPosition,... 'horizontal','left',... 'BackgroundColor', 'w',... 'String', 'myResult.ps',... 'callback',@CallBack_saveResultPSEdit,... 'visible','off'); handles.loadImagePush = uicontrol(handles.figure,'style','push',... 'unit','normalized','position',loadImagePushPosition,... 'string','Load Image','callback',@CallBack_loadImagePush,... 'visible','off'); handles.saveImagePush = uicontrol(handles.figure,'style','push',... 'unit','normalized','position',saveImagePushPosition,... 'string','Save Image','callback',@CallBack_saveImagePush,... 'visible','off'); handles.saveResultPSPush = uicontrol(handles.figure,'style','push',... 'unit','normalized','position',saveResultPSPushPosition,... 'string','Save Result','callback',@CallBack_saveResultPSPush,... 'visible','off'); handles.getStructurePush = uicontrol(handles.figure,'style','push',... 'unit','normalized','position',getStructurePushPosition,... 'string','Get Structure','callback',@CallBack_getStructurePush,'visible','off'); handles.structureEdit = uicontrol(handles.figure,'style','edit',... 'unit','normalized','position',structureEditPosition,... 'horizontal','center',... 'enable', 'on',... 'UserData',struct(... 'hReg', [],... 'M', M,... 'D', DIM,... 'xyz', [0 0 0] )); handles.pickThisClusterPush = uicontrol(handles.figure,'style','push',... 'unit','normalized','position',pickThisClusterPushPosition,... 'string','Pick Cluster/Info','callback',@CallBack_pickThisClusterPush); handles.selectThisClusterPush = uicontrol(handles.figure,'style','push',... 'unit','normalized','position',selectThisClusterPushPosition,... 'string','Select Cluster','callback',@CallBack_selectThisClusterPush); handles.clearSelectedClusterPush = uicontrol(handles.figure,'style','push',... 'unit','normalized','position',clearSelectedClusterPushPosition,... 'string','Clear Selection','callback',@CallBack_clearSelectedClusterPush); handles.displayIntensityText = uicontrol(handles.figure,'style','text',... 'unit','normalized','position',displayIntensityTextPosition,... 'string','display intensity','horizontal','left'); handles.allIntensityRadio = uicontrol(handles.figure,'style','radio',... 'unit','normalized',... 'string','All',... 'position',allIntensityRadioPosition,... 'value', 1,... 'callback',@CallBack_allIntensityRadio); handles.positiveIntensityRadio = uicontrol(handles.figure,'style','radio',... 'unit','normalized',... 'string','Only +',... 'position',positiveIntensityRadioPosition,... 'callback',{@CallBack_allIntensityRadio,'+'}); handles.negativeIntensityRadio = uicontrol(handles.figure,'style','radio',... 'unit','normalized',... 'string','Only -',... 'position',negativeIntensityRadioPosition,... 'callback',{@CallBack_allIntensityRadio,'-'}); handles.renderViewCheck = uicontrol(handles.figure,'style','checkbox',... 'unit','normalized',... 'string','Render View' ,... 'horizontal', 'right',... 'position',renderViewCheckPosition,... 'callback', @CallBack_renderViewCheck); handles.sectionViewListbox = uicontrol(handles.figure,'style','listbox',... 'unit','normalized',... 'String', {'single T1','avg152PD','avg152T1','avg152T2','avg305T1','ch2','ch2bet','aal','brodmann'}, ... 'value',3,... 'position',sectionViewListboxPosition,... 'callback',@CallBack_sectionViewListbox); handles.xHairCheck = uicontrol(handles.figure,'style','checkbox',... 'unit','normalized',... 'string','XHairs Off' ,... 'horizontal','left',... 'position',xHairCheckPosition,... 'callback',@CallBack_xHairCheck); handles.sectionViewMoreTargetPush = uicontrol(handles.figure,'style','push',... 'unit','normalized','position',sectionViewMoreTargetPushPosition,... 'string','other ...','callback',@CallBack_sectionViewMoreTargetPush); handles.setTRangeEdit = uicontrol(handles.figure,'style','edit',... 'unit','normalized','position',setTRangeEditPosition,'BackgroundColor', 'w',... 'string','auto','callback',@CallBack_setTRangeEdit); handles.setTRangeText = uicontrol(handles.figure,'style','text',... 'unit','normalized','position',setTRangeTextPosition,... 'string','colorbar max'); handles.hideControlPush = uicontrol(handles.figure, 'style', 'push',... 'unit','normalized',... 'String', '<', 'position', hideControlPushPosition,... 'visible','off'); handles.volumePush = uicontrol(handles.figure, 'style', 'push',... 'unit','normalized',... 'String', 'volume', ... 'position', volumePushPosition,... 'callback', @CallBack_volumePush); handles.commonRegionPush = uicontrol(handles.figure, 'style', 'push',... 'unit','normalized',... 'String', 'common region', ... 'position', commonRegionPushPosition,... 'callback', @CallBack_commonRegionPush); handles.displayPush = uicontrol(handles.figure, 'style', 'push',... 'unit','normalized',... 'String', 'display', ... 'position', displayPushPosition,... 'callback', @CallBack_displayPush,... 'visible','off'); handles.allinonePush = uicontrol(handles.figure, 'style', 'push',... 'unit','normalized',... 'String', 'all in one', ... 'position', allinonePushPosition,... 'callback', @CallBack_allinonePush,... 'visible','off'); handles.searchPush = uicontrol(handles.figure, 'style','push',... 'unit','normalized','position',searchPushPosition,... 'String', 'search','callback',@CallBack_searchPush, 'ForeGroundColor',[0 0 1]); handles.searchContentEdit = uicontrol(handles.figure, 'style','edit',... 'unit','normalized','position',searchContentEditPosition,... 'ForeGroundColor',[0 0 1],... 'BackgroundColor', 'w',... 'horizontal','left'); handles.searchText = uicontrol(handles.figure, 'style','text',... 'unit','normalized','position',searchTextPosition,... 'string', ' in',... 'horizontal','left',... 'visible','off'); handles.searchEnginePop = uicontrol(... 'Units','normalized', ... 'ListboxTop',0, ... 'Position',searchEnginePopPosition, ... 'String',{'in xBrain.org';'in google scholar';'in pubmed';'in wiki'}, ... 'Style','popupmenu', ... 'value',1); handles.overlayPush = uicontrol(handles.figure, 'style','push',... 'unit','normalized','position',overlayPushPosition,... 'String', 'overlay','callback',@CallBack_overlayPush); handles.overlayEdit = uicontrol(handles.figure, 'style','edit',... 'unit','normalized','position',overlayEditPosition,... 'BackgroundColor', 'w',... 'horizontal','left',... 'callback', @CallBack_overlayEdit); handles.overlayPop = uicontrol(handles.figure, 'style','popupmenu',... 'unit','normalized','position',overlayPopPosition,... 'string', sort(fieldnames(handles.wholeMaskMNIAll)),... 'horizontal','left',... 'callback', @CallBack_overlayPop); handles.helpPush = uicontrol(handles.figure, 'style','push',... 'unit','normalized','position',helpPosition,... 'String', 'help','callback','web http://people.hnl.bcm.tmc.edu/cuixu/xjView','ForeGroundColor',[0 0 1],... 'horizontal','left', ... 'visible','off'); handles.infoTextBox = uicontrol(handles.figure, 'style','edit',... 'unit','normalized','position',infoTextBoxPosition,... 'String', 'Welcome to xjView 4','ForeGroundColor','k', 'BackgroundColor', 'w',... 'horizontal','left', ...'fontname','times',... 'max',2, 'min',0); try urlread('http://people.hnl.bcm.edu/cuixu/xjView/guestbook/stat.php'); s = urlread('http://people.hnl.bcm.tmc.edu/cuixu/xjView/toUser.txt'); set(handles.infoTextBox, 'String', s); end handles.glassViewAxes = axes('unit','normalized','position',glassViewAxesPosition,'XTick',[],'YTick',[],'visible','off'); handles.testEdit = uicontrol(handles.figure,'style','edit',... 'unit','normalized','position',[0.1 0.4 0.2 0.05],... 'horizontal','left',... 'callback',@test,... 'visible','off'); % menu cSHH = get(0,'ShowHiddenHandles'); set(0,'ShowHiddenHandles','on') hMenuFile = findobj(get(handles.figure,'Children'),'flat','Label','&File'); if ~isempty(hMenuFile) hMenuFileOpen = findobj(get(handles.figure,'Children'),'Label','&Open...'); set(hMenuFileOpen, 'label', 'Open Figure...'); hMenuFileSave = findobj(get(handles.figure,'Children'),'Label','&Save'); set(hMenuFileSave, 'label', 'Save Figure ...'); hMenuFileSaveAs = findobj(get(handles.figure,'Children'),'Label','Save &As...'); set(hMenuFileSaveAs, 'label', 'Save Figure As ...'); else hMenuFile = uimenu(handles.figure, 'label', '&File'); end set(hMenuFile,'ForegroundColor',[0 0 1]); set(findobj(hMenuFile,'Position',1),'Separator','on'); uimenu('Parent',hMenuFile,'Position',1,'ForegroundColor',[0 0 1],... 'Label','Open Images (*.img) ...',... 'CallBack',@CallBack_loadImagePush, 'Accelerator', 'o'); uimenu('Parent',hMenuFile,'Position',2,'ForegroundColor',[0 0 1],... 'Label','Save Current Image (*.img) ...',... 'CallBack',{@CallBack_saveImagePush, '', 0}); uimenu('Parent',hMenuFile,'Position',3,'ForegroundColor',[0 0 1],... 'Label','Save Current Image as Mask (*.img) ...',... 'CallBack',{@CallBack_saveImagePush, '', 1}); uimenu('Parent',hMenuFile,'Position',4,'ForegroundColor',[0 0 1],... 'Label','Save Result (*.ps/pdf) ...',... 'CallBack',@CallBack_saveResultPSPush); hMenuHelp = findobj(get(handles.figure,'Children'),'flat','Label','&Help'); if isempty(hMenuHelp) hMenuHelp = uimenu(handles.figure, 'label', 'xjView &Help'); end set(hMenuHelp,'ForegroundColor',[0 0 1]); uimenu('Parent',hMenuHelp,'Position',1,'ForegroundColor',[0 0 1],... 'Label','xBrain.org: brain mapping database',... 'CallBack','web http://www.xbrain.org -browser'); uimenu('Parent',hMenuHelp,'Position',2,... 'Label','xjview help','ForegroundColor',[0 0 1],... 'CallBack','web http://people.hnl.bcm.tmc.edu/cuixu/xjView'); set(findobj(hMenuHelp,'Position',3),'Separator','on'); set(0,'ShowHiddenHandles',cSHH) if exist('cuixuBOLDretrieve') hMenuAnalyze = uimenu('label','&Analyze','ForegroundColor',[0 0 1],'visible','on'); hMenuPreprocess = uimenu(hMenuAnalyze,'label','Preprocess','ForegroundColor',[0 0 1],'callback', @CallBack_preprocess); hMenuProcess = uimenu(hMenuAnalyze,'label','Process (GLM estimation)','ForegroundColor',[0 0 1],'callback',@CallBack_process); hMenuSPMProcess = uimenu(hMenuAnalyze,'label','SPMProcess (GLM using SPM)','ForegroundColor',[0 0 1],'callback',@CallBack_SPMProcess); hMenuGLMPeak = uimenu(hMenuAnalyze,'label','GLM on peak BOLD','ForegroundColor',[0 0 1],'callback',@CallBack_GLMPeak); hMenuContrast = uimenu(hMenuAnalyze,'label','Contrast','ForegroundColor',[0 0 1],'callback',@CallBack_contrast); hMenuFDR = uimenu(hMenuAnalyze,'label','FDR','ForegroundColor',[0 0 1],'callback',@CallBack_fdr); hMenuROI = uimenu(hMenuAnalyze,'label','ROI: retrieve signal','ForegroundColor',[0 0 1],'callback',@CallBack_timeSeries); hMenuROIPlot = uimenu(hMenuAnalyze,'label','ROI: plot','ForegroundColor',[0 0 1],'callback',@CallBack_plotROI, 'Accelerator', 'm'); hMenuROIIndividualPlot = uimenu(hMenuAnalyze,'label','ROI: individual plot','ForegroundColor',[0 0 1],'callback',@CallBack_plotIndividualROI); hMenuROIIndividualPlotWithBehavior = uimenu(hMenuAnalyze,'label','ROI: individual plot with behavior','ForegroundColor',[0 0 1],'callback',@CallBack_plotIndividualROIWithBehavior); hMenuROICorrelationPlot = uimenu(hMenuAnalyze,'label','ROI: correlation plot','ForegroundColor',[0 0 1],'callback',@CallBack_plotCorrelationROI); %hMenuWholeBrainCorrelation = uimenu(hMenuAnalyze,'label','Whole brain correlation','ForegroundColor',[0 0 1],'callback',@CallBack_wholeBrainCorrelation); hMenuBehaviorAnalysis = uimenu(hMenuAnalyze,'label','Behavior analsyis','ForegroundColor',[0 0 1],'callback',@CallBack_behaviorAnalysis); hMenuHeadMovementAnalysis = uimenu(hMenuAnalyze,'label','Head movement analsyis','ForegroundColor',[0 0 1],'callback',@CallBack_headMovementAnalysis); hMenuModelComparison = uimenu(hMenuAnalyze,'label','Linear model comparison','ForegroundColor',[0 0 1],'callback',@CallBack_modelComparison); hMenuHNLOnly = uimenu('label','For H&NL Only','ForegroundColor',[0 0 1],'visible','on'); hMenuNew2Old = uimenu(hMenuHNLOnly,'label','Format convert','ForegroundColor',[0 0 1],'callback',@CallBack_new2old); hMenuPreprocessCluster = uimenu(hMenuHNLOnly,'label','Preprocess (on cluster)','ForegroundColor',[0 0 1],'callback',{@CallBack_preprocess, 'cluster'}); hMenuProcessCluster = uimenu(hMenuHNLOnly,'label','Process (GLM, on cluster)','ForegroundColor',[0 0 1],'callback',{@CallBack_process, 'cluster'}); hMenuSPMProcessCluster = uimenu(hMenuHNLOnly,'label','SPM Process (GLM using SPM, on cluster)','ForegroundColor',[0 0 1],'callback',{@CallBack_SPMProcess, 'cluster'}); hMenuGLMPeakCluster = uimenu(hMenuHNLOnly,'label','GLM on peak BOLD (on cluster)','ForegroundColor',[0 0 1],'callback',{@CallBack_GLMPeak, 'cluster'}); end figurecm = uicontextmenu; uimenu(figurecm,'label','Red','callback','set(gcf,''color'',''r'')'); uimenu(figurecm,'label','White','callback','set(gcf,''color'',''w'')'); uimenu(figurecm,'label','Gray','callback','set(gcf,''color'',[0.925, 0.914, 0.847])'); %set(handles.figure,'uicontextmenu',figurecm); set(handles.figure,'WindowButtonDownFcn',@figureMouseUpFcn); set(handles.figure,'visible','on'); % save pre-set values handles.system = os; handles.spmdir = spmdir; handles.screenResolution = screenResolution; handles.pValue = pValue; handles.intensityThreshold = intensityThreshold; handles.clusterSizeThreshold = clusterSizeThreshold; handles.sectionViewPosition = sectionViewPosition; handles.sectionViewTargetFile = getSectionViewTargetFile(spmdir, 'avg152T1'); guidata(f, handles); % global variables for rotation matrix M and dimension global M_; global DIM_; global TR_; global LEFTRIGHTFLIP_; global TMAX_; % colorbar max to display in section view M_ = M; DIM_ = DIM; TR_ = TR; LEFTRIGHTFLIP_ = leftrightflip; TMAX_ = 'auto'; % check input arguments if length(varargin) == 0 []; elseif isstr(varargin{1}) CallBack_loadImagePush(handles.loadImagePush, [], varargin); else mniCoord = varargin{1}; if length(varargin) < 2 intensity = ones(size(mniCoord,1),1); else intensity = varargin{2}; end thisStruct.mni = mniCoord; thisStruct.intensity = intensity; thisStruct.M = M; thisStruct.DIM = DIM'; CallBack_loadImagePush(handles.loadImagePush, [], thisStruct); end function test(hObject, eventdata) handles = guidata(gcbo); set(hObject, 'String', num2str(handles.pValue)); vars = evalin('base','who'); vars x = evalin('base',vars{1}); x handles.DIM %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% FDR %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function CallBack_fdr(hObject, eventdata) handles = guidata(hObject); set(handles.infoTextBox, 'string', {'Right now FDR only works for T-test image.'}); if length(handles.imageFileName) > 1 set(handles.infoTextBox, 'string', {'I can only work for a single image file. You opened multiple files.'}); return end q = get(handles.pValueEdit,'String'); q = str2num(q); if get(handles.allIntensityRadio, 'Value') positive = 1; elseif get(handles.positiveIntensityRadio, 'Value') positive = 1; elseif get(handles.negativeIntensityRadio, 'Value') positive = -1; end xjviewpath = fileparts(which('xjview')); maskImageFile = fullfile(xjviewpath, 'mask.img'); [threshold, pvalue] = fdr(handles.imageFileName{1}, q, positive, maskImageFile); set(handles.pValueEdit,'string',pvalue); CallBack_pValueEdit(handles.pValueEdit, eventdata); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% model comparison %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function CallBack_modelComparison(hObject, eventdata) answer = getVariable({'y','x (full model)', 'x (reduced model)'}); if isempty(answer) return; end if ~isempty(answer{1}) y = evalin('base',answer{1}); else return; end if ~isempty(answer{2}) xf = evalin('base',answer{2}); % full model else return; end if ~isempty(answer{3}) xr = evalin('base',answer{3}); % reduced model else xr = []; end % make vector column vector [r, c] = size(y); if r==1; y = y'; end [r, c] = size(xf); if r(0.5+ii/10); end K = {zeros(1, size(C,1)),zeros(1, size(C,1)),zeros(1, size(C,1)),zeros(1, size(C,1))}; for ii=1:size(C,1) for jj=1:4 K{jj}(ii) = sum(CC{jj}(ii,:)) - 1; end end x=[0:size(C,1)]; for jj=1:4 y{jj}=zeros(size(x)); end for ii=1:length(x) for jj=1:4 y{jj}(ii) = sum(K{jj} == x(ii)); end end figure; loglog(x,y{1}, x, y{2}, x, y{3}, x, y{4}); xlabel('degree'); ylabel('counts'); legend('0.6', '0.7', '0.8', '0.9'); axis equal z = sum(abs(C))-1; zx = 0:max(z); for ii=1:length(zx)-1 pos = find(z>zx(ii) & z<=zx(ii+1)); zy(ii) = length(pos); end figure; loglog(zx(1:length(zy)),zy); xlabel('weighted degree'); ylabel('counts'); axis equal xjview(cor2mni(coord, handles.M{1}), z); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% get/select variable names in base workspace %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function vars = getVariable(titles) vars = evalin('base','who'); height = 0.07; f = dialog('unit','normalized', 'menubar','none', 'position', [0.3 0.2 0.4 0.4], 'name', 'pick variables', 'NumberTitle','off'); uicontrol(f,'style','text',... 'unit','normalized',... 'String', 'Available variables', ... 'position',[0 0.9 0.5 0.1/2]); variableListbox = uicontrol(f,'style','listbox','tag','variableListbox',... 'unit','normalized',... 'String', vars, ... 'value',1,... 'position',[0 0 0.5 0.9]); okPush = uicontrol(f,'style','push',... 'unit','normalized',... 'String', 'OK', ... 'position',[0.55 0.05 0.2 height],... 'callback','uiresume'); cancelPush = uicontrol(f,'style','push',... 'unit','normalized',... 'String', 'Cancel', ... 'position',[0.75 0.05 0.2 height],... 'callback','delete(gcf)'); uicontrol(f,'style','text',... 'unit','normalized',... 'String', titles{1}, ... 'position',[0.5 0.9 0.5 0.1/2]); imageDataPush = uicontrol(f,'style','push',... 'unit','normalized',... 'String', '->', ... 'position',[0.5 0.8 0.1 height],... 'callback', [... 'xyouneverfindme=findobj(get(gcf,''Children''),''flat'',''tag'',''imageDataEdit'');'... 'yyouneverfindme=findobj(get(gcf,''Children''),''flat'',''tag'',''variableListbox'');'... 'allyouneverfindme=get(yyouneverfindme,''string'');'... 'selectedyouneverfindme=allyouneverfindme{get(yyouneverfindme,''value'')};'... 'set(xyouneverfindme,''string'',selectedyouneverfindme);'... 'clear allyouneverfindme selectedyouneverfindme xyouneverfindme yyouneverfindme;']); imageDataEdit = uicontrol(f,'style','edit','tag','imageDataEdit',... 'unit','normalized',... 'String', '', ... 'BackgroundColor', 'w',... 'position',[0.6 0.8 0.3 height]); if length(titles)>=2 uicontrol(f,'style','text',... 'unit','normalized',... 'String', titles{2}, ... 'position',[0.5 0.7 0.5 0.1/2]); eventDataPush = uicontrol(f,'style','push',... 'unit','normalized',... 'String', '->', ... 'position',[0.5 0.6 0.1 height],... 'callback', [... 'xyouneverfindme=findobj(get(gcf,''Children''),''flat'',''tag'',''eventDataEdit'');'... 'yyouneverfindme=findobj(get(gcf,''Children''),''flat'',''tag'',''variableListbox'');'... 'allyouneverfindme=get(yyouneverfindme,''string'');'... 'selectedyouneverfindme=allyouneverfindme{get(yyouneverfindme,''value'')};'... 'set(xyouneverfindme,''string'',selectedyouneverfindme);'... 'clear allyouneverfindme selectedyouneverfindme xyouneverfindme yyouneverfindme;']); eventDataEdit = uicontrol(f,'style','edit','tag','eventDataEdit',... 'unit','normalized',... 'String', '', ... 'BackgroundColor', 'w',... 'position',[0.6 0.6 0.3 height]); end if length(titles)>=3 uicontrol(f,'style','text',... 'unit','normalized',... 'String', titles{3}, ... 'position',[0.5 0.5 0.5 0.1/2]); correlatorDataPush = uicontrol(f,'style','push',... 'unit','normalized',... 'String', '->', ... 'position',[0.5 0.4 0.1 height],... 'callback', [... 'xyouneverfindme=findobj(get(gcf,''Children''),''flat'',''tag'',''correlatorDataEdit'');'... 'yyouneverfindme=findobj(get(gcf,''Children''),''flat'',''tag'',''variableListbox'');'... 'allyouneverfindme=get(yyouneverfindme,''string'');'... 'selectedyouneverfindme=allyouneverfindme{get(yyouneverfindme,''value'')};'... 'set(xyouneverfindme,''string'',selectedyouneverfindme);'... 'clear allyouneverfindme selectedyouneverfindme xyouneverfindme yyouneverfindme;']); correlatorDataEdit = uicontrol(f,'style','edit','tag','correlatorDataEdit',... 'unit','normalized',... 'String', '', ... 'BackgroundColor', 'w',... 'position',[0.6 0.4 0.3 height]); end if length(titles)>=4 uicontrol(f,'style','text',... 'unit','normalized',... 'String', titles{4}, ... 'position',[0.5 0.3 0.5 0.1/2]); otherDataPush = uicontrol(f,'style','push',... 'unit','normalized',... 'String', '->', ... 'position',[0.5 0.2 0.1 height],... 'callback', [... 'xyouneverfindme=findobj(get(gcf,''Children''),''flat'',''tag'',''otherDataEdit'');'... 'yyouneverfindme=findobj(get(gcf,''Children''),''flat'',''tag'',''variableListbox'');'... 'allyouneverfindme=get(yyouneverfindme,''string'');'... 'selectedyouneverfindme=allyouneverfindme{get(yyouneverfindme,''value'')};'... 'set(xyouneverfindme,''string'',selectedyouneverfindme);'... 'clear allyouneverfindme selectedyouneverfindme xyouneverfindme yyouneverfindme;']); otherDataEdit = uicontrol(f,'style','edit','tag','otherDataEdit',... 'unit','normalized',... 'String', '', ... 'BackgroundColor', 'w',... 'position',[0.6 0.2 0.3 height]); end uiwait(f); try var{1} = get(imageDataEdit,'string'); if length(titles)>=2 var{2} = get(eventDataEdit,'string'); end if length(titles)>=3 var{3} = get(correlatorDataEdit,'string'); end if length(titles)>=4 var{4} = get(otherDataEdit,'string'); end vars = var; delete(f); catch vars = {}; try delete(f); end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% quit xjview %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function CallBack_quit(hObject, eventdata, warnstate) warning(warnstate) % try % rmdir('xjviewtmp'); % end delete(gcf); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% mouse double click %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function figureMouseUpFcn(hObject, eventdata) status = get(hObject, 'SelectionType'); % double click if strcmp(status, 'open') handles = guidata(hObject); CallBack_loadImagePush(handles.loadImagePush, eventdata); else return end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% change edit image file name %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function CallBack_imageFileEdit(hObject, eventdata) handles = guidata(hObject); filename = get(hObject, 'String'); filename = str2cell(filename); CallBack_loadImagePush(handles.loadImagePush, eventdata, filename); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% click load image file button %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function CallBack_loadImagePush(hObject, eventdata, thisfilename) handles = guidata(hObject); handles.imageFileName=[]; handles.M=[]; handles.DIM=[]; handles.TF=[]; handles.df=[]; handles.mni=[]; handles.intensity=[]; handles.currentmni=[]; handles.currentintensity=[]; handles.currentDisplayMNI=[]; handles.currentDisplayIntensity=[]; if ~exist('thisfilename') thisfilename = ''; end if isstruct(thisfilename) handles.imageFileName = {''}; handles.mni = {thisfilename.mni}; handles.intensity = {thisfilename.intensity}; handles.M = {thisfilename.M}; handles.DIM = {thisfilename.DIM}; handles.TF = {'S'}; handles.df = {1e6}; handles.pValue = 1; set(handles.pValueEdit, 'string', '1'); handles.clusterSizeThreshold = 0; set(handles.clusterSizeThresholdEdit, 'String', '0'); else [handles.imageFileName, handles.M, handles.DIM, handles.TF, handles.df, handles.mni, handles.intensity] = getImageFile(thisfilename); end if isempty(handles.imageFileName) return end different = 0; % image files are same or different? if length(handles.TF)>1 for ii=1:length(handles.TF) if strcmp(handles.TF{ii},handles.TF{1}) & isequal(handles.df{ii},handles.df{1}) & isequal(handles.M{ii},handles.M{1}) & isequal(handles.DIM{ii},handles.DIM{1}) continue; else warndlg('Images are from different statistics or sources.', 'Warning'); %set(handles.infoTextBox, 'string', 'Images are from different statistics or sources.'); beep; different = 1; break; end end end % reset files with empty df/TF to df=1 and TF='S'. 'S'=='T' but has a tag % meaning it is changed. resetTF = 0; for ii=1:length(handles.TF) if isempty(handles.TF{ii}) handles.TF{ii} = 'S'; resetTF = 1; end if isempty(handles.df{ii}) | isequal(handles.df{ii},0) handles.df{ii} = 1e6; resetTF = 1; end end handles.currentmni = handles.mni; handles.currentintensity = handles.intensity; set(handles.dfEdit, 'String', cell2str(handles.df)); set(handles.imageFileEdit, 'String', cell2str(handles.imageFileName)); % s=-log10(p) maxs = maxcell(t2s(cellmax(handles.intensity,'abs'),handles.df, handles.TF),'abs'); if isinf(maxs); maxs = 20; end set(handles.slider, 'Max', maxs, 'Min', 0, 'sliderstep',[min(maxs/100,0.05),min(maxs/100,0.05)]); if handles.TF{1}=='T' & different == 0 str = [blanks(length(' intensit')) 'T=']; elseif handles.TF{1}=='F' & different == 0 str = [blanks(length(' intensit')) 'F=']; else str=' intensity='; end set(handles.intensityThresholdText, 'String', str); set(handles.figure,'Name',['xjView: ' cell2str(handles.imageFileName)]); try for ii=1:length(handles.hLegend) delete(handles.hLegend{ii}); end end if length(handles.TF)>1 colours = repmat([1 0 0;1 1 0;0 1 0;0 1 1;0 0 1;1 0 1],100,1); for ii=1:min(length(handles.TF),10) [tmp,filename] = fileparts(handles.imageFileName{ii}); if ii == 10; filename = '......'; end pos0 = handles.sectionViewPosition; pos(1) = pos0(1)+pos0(3)/2+0.03; pos(2) = pos0(2)+ii/50-0.03; pos(3) = 0.12; pos(4) = 0.02; handles.hLegend{ii}=uicontrol(handles.figure, 'style','text',... 'unit','normalized','position',pos,... 'string', filename,... 'horizontal','left',... 'fontweight','bold',... 'ForeGroundColor',colours(ii,:)); end c_names = {'red';'yellow';'green';'cyan';'blue';'magenta'}; end guidata(hObject, handles); global M_; global DIM_; M_ = handles.M{1}; DIM_ = handles.DIM{1}; if resetTF==1 set(handles.pValueEdit,'string',1); end CallBack_pValueEdit(handles.pValueEdit, eventdata); % display info try urlread('http://people.hnl.bcm.edu/cuixu/xjView/guestbook/stat.php'); s = urlread('http://people.hnl.bcm.tmc.edu/cuixu/xjView/toUser.txt'); report{1} = s; catch report{1} = 'Welcome to xjView 4'; end for jj=1:length(handles.imageFileName) report{2+6*(jj-1)} = cell2str(handles.imageFileName(jj)); if handles.TF{jj} == 'T' | handles.TF{jj} == 'F' report{3+6*(jj-1)} = ['This is a ' handles.TF{jj} ' test image.']; else report{3+6*(jj-1)} = '';%['I don''t know what test this image came from.']; end report{4+6*(jj-1)} = 'mat = '; report{5+6*(jj-1)} = num2str(handles.M{jj}); report{6+6*(jj-1)} = 'dimension = '; report{7+6*(jj-1)} = num2str(handles.DIM{jj}); end set(handles.infoTextBox, 'string', report); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% pValueEdit %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function CallBack_pValueEdit(hObject, eventdata) handles = guidata(hObject); tmp = str2double(get(hObject, 'String')); tmps = -log10(tmp); if isnan(tmp) | tmp < 0 | tmp > 1 errordlg('I don''t understand the input.','error'); set(hObject, 'String', handles.pValue); return end if tmps>get(handles.slider,'max') | tmps maxcell(cellmax(handles.intensity,'abs')) tmp = maxcell(cellmax(handles.intensity,'abs')); end handles.pValue = t2p(tmp, handles.df{1}, handles.TF{1}); handles.intensityThreshold = p2t(num2cell(handles.pValue*ones(1,length(handles.TF))), handles.df, handles.TF); set(handles.slider,'Value', -log10(handles.pValue)); set(handles.intensityThresholdEdit, 'String', cell2str(handles.intensityThreshold)); guidata(hObject, handles); CallBack_slider(hObject, eventdata, -log10(handles.pValue)); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% slider bar %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function CallBack_slider(hObject, eventdata, value) handles = guidata(hObject); if exist('value') s = value; if s > get(handles.slider,'max') s = get(handles.slider,'max')*0.99; end if s < get(handles.slider,'min') s = get(handles.slider,'min'); end else s = get(hObject,'Value'); end set(handles.slider, 'value', s); pvalue = 10^(-s); set(handles.pValueEdit,'String',num2str(pvalue)); t = p2t(num2cell(pvalue*ones(1,length(handles.TF))), handles.df, handles.TF); handles.intensityThreshold = t; set(handles.intensityThresholdEdit, 'String', cell2str(handles.intensityThreshold)); handles.pValue = pvalue; for ii=1:length(handles.TF) pos{ii} = find(abs(handles.intensity{ii})>=t{ii}); handles.currentintensity{ii} = handles.intensity{ii}(pos{ii}); handles.currentmni{ii} = handles.mni{ii}(pos{ii},:); end guidata(hObject,handles); if get(handles.allIntensityRadio, 'Value') CallBack_allIntensityRadio(handles.allIntensityRadio, eventdata); elseif get(handles.positiveIntensityRadio, 'Value') CallBack_allIntensityRadio(handles.positiveIntensityRadio, eventdata, '+'); elseif get(handles.negativeIntensityRadio, 'Value') CallBack_allIntensityRadio(handles.negativeIntensityRadio, eventdata, '-'); end set(handles.infoTextBox, 'string', {'Don''t drag the slider bar too fast. Release your mouse button at least 1 second later.', ... 'This sounds stupid. But there is a bug (probably MatLab bug) which I can'' fix right now.', ... 'I suggest you confirm the correctness of the current display by press Enter in the pValue edit box.'}); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% display intensity all+- radios %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function CallBack_allIntensityRadio(hObject, eventdata, pnall) % pnall = '+', '-', or 'c'. c means current (simply update drawing) % handles = guidata(hObject); currentselect = []; if get(handles.allIntensityRadio, 'Value'); currentselect = handles.allIntensityRadio; thispnall = 'a'; end if get(handles.positiveIntensityRadio, 'Value'); currentselect = handles.positiveIntensityRadio; thispnall = '+'; end if get(handles.negativeIntensityRadio, 'Value'); currentselect = handles.negativeIntensityRadio; thispnall = '-'; end set(handles.allIntensityRadio, 'Value', 0); set(handles.positiveIntensityRadio, 'Value', 0); set(handles.negativeIntensityRadio, 'Value', 0); if exist('pnall') if pnall=='c' hObject = currentselect; pnall = thispnall; end end set(hObject, 'Value', 1); if ~isfield(handles,'currentintensity') return end for ii=1:length(handles.TF) if exist('pnall') if pnall == '-' pos{ii} = find(handles.currentintensity{ii} < 0); elseif pnall == '+' pos{ii} = find(handles.currentintensity{ii} > 0); elseif pnall == 'a' pos{ii} = 1:length(handles.currentintensity{ii}); end else pos{ii} = 1:length(handles.currentintensity{ii}); end intensity{ii} = handles.currentintensity{ii}(pos{ii}); mni{ii} = handles.currentmni{ii}(pos{ii},:); cor{ii} = mni2cor(mni{ii}, handles.M{ii}); if ~isempty(cor{ii}) A = spm_clusters(cor{ii}'); pos0 = []; for kk = 1:max(A) jj = find(A == kk); if length(jj) >= handles.clusterSizeThreshold; pos0 = [pos0 jj]; end end handles.currentDisplayMNI{ii} = mni{ii}(pos0,:); handles.currentDisplayIntensity{ii} = intensity{ii}(pos0); else handles.currentDisplayMNI{ii} = mni{ii}([],:); handles.currentDisplayIntensity{ii} = intensity{ii}([]); end end [handles.hReg, handles.hSection, handles.hcolorbar] = Draw(handles.currentDisplayMNI, handles.currentDisplayIntensity, hObject, handles); if get(handles.allIntensityRadio, 'Value') & max(handles.currentDisplayIntensity{1}) < 0 warndlg('No supra-threshold positive intensity. Only negative intensity is displayed.'); end try set(handles.figure,'currentaxes', handles.glassViewAxes); xrange = xlim; yrange = ylim; try delete(handles.hGlassText) end if ~isempty(handles.selectedCluster,1) %handles.hGlassText = text(xrange(1)+diff(xrange)*0.6, yrange(1)+diff(yrange)*0.9, [num2str(size(handles.selectedCluster,1)) ' clusters selected']); set(handles.infoTextBox, 'string', [num2str(size(handles.selectedCluster,1)) ' clusters selected']); end end guidata(hObject, handles); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% render view check? %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function CallBack_renderViewCheck(hObject, eventdata) check = get(hObject, 'Value'); if check CallBack_allIntensityRadio(hObject, eventdata, 'c'); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% which section view target file? list box %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function CallBack_sectionViewListbox(hObject, eventdata) handles = guidata(hObject); contents = get(handles.sectionViewListbox,'String'); currentsel = contents{get(handles.sectionViewListbox,'Value')}; handles.sectionViewTargetFile = getSectionViewTargetFile(handles.spmdir, currentsel); guidata(hObject, handles); CallBack_allIntensityRadio(hObject, eventdata, 'c'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% get sectionviewtargetfile %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function sectionViewTargetFile = getSectionViewTargetFile(spmdir, selectedcontent) if findstr('SPM2',spm('ver')) fileext = 'mnc'; elseif findstr('SPM5',spm('ver')) fileext = 'nii'; end currentsel = selectedcontent; if ~isempty(strfind(currentsel, 'single')) sectionViewTargetFile = fullfile(spmdir, 'canonical', ['single_subj_T1.' fileext]); elseif ~isempty(strfind(currentsel, '152PD')) sectionViewTargetFile = fullfile(spmdir, 'canonical', ['avg152PD.' fileext]); elseif ~isempty(strfind(currentsel, '152T1')) sectionViewTargetFile = fullfile(spmdir, 'canonical', ['avg152T1.' fileext]); elseif ~isempty(strfind(currentsel, '152T2')) sectionViewTargetFile = fullfile(spmdir, 'canonical', ['avg152T2.' fileext]); elseif ~isempty(strfind(currentsel, '305T1')) sectionViewTargetFile = fullfile(spmdir, 'canonical', ['avg305T1.' fileext]); elseif strcmp(currentsel, 'ch2') sectionViewTargetFile = fullfile(spmdir, 'canonical', 'ch2.img'); elseif strcmp(currentsel, 'ch2bet') sectionViewTargetFile = fullfile(spmdir, 'canonical', 'ch2bet.img'); elseif strcmp(currentsel, 'aal') sectionViewTargetFile = fullfile(spmdir, 'canonical', 'aal.img'); elseif strcmp(currentsel, 'brodmann') sectionViewTargetFile = fullfile(spmdir, 'canonical', 'brodmann.img'); end return %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% xhairs in section view? %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function CallBack_xHairCheck(hObject, eventdata) check = get(hObject, 'Value'); if check spm_orthviews('Xhairs','off'); else spm_orthviews('Xhairs','on'); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% other target file for section view, push button %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function CallBack_sectionViewMoreTargetPush(hObject, eventdata) handles = guidata(hObject); [filename, pathname, filterindex] = uigetfile('*', 'Pick an target file'); if isequal(filename,0) | isequal(pathname,0) return; end handles.sectionViewTargetFile = fullfile(pathname, filename); guidata(hObject, handles); CallBack_allIntensityRadio(hObject, eventdata, 'c'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% set colorbar range %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function CallBack_setTRangeEdit(hObject, eventdata) global TMAX_; handles = guidata(hObject); TMAX_ = get(hObject, 'String'); if isempty(str2num(TMAX_)) && ~strcmp(TMAX_, 'auto') return; end guidata(hObject, handles); CallBack_allIntensityRadio(hObject, eventdata, 'c'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% change degree of freedome %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function CallBack_dfEdit(hObject, eventdata) handles = guidata(hObject); tmp = str2cell(get(hObject, 'String')); if iscellstr(tmp) errordlg('Please input a valid number.','error'); try set(hObject, 'String', handles.df); catch set(hObject, 'String', ''); end return end handles.df=tmp; if isfield(handles,'TF') t = p2t(mat2cell(handles.pValue*ones(1,length(handles.TF))), handles.df, handles.TF); handles.intensityThreshold = t; set(handles.intensityThresholdEdit, 'String', cell2str(t)); end guidata(hObject, handles); CallBack_pValueEdit(handles.pValueEdit, eventdata); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% get structure push %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function CallBack_getStructurePush(hObject, eventdata) handles = guidata(hObject); xyz = spm_XYZreg('GetCoords',handles.hReg); tmp_coor = cuixuFindStructure(xyz', handles.DB); set(handles.structureEdit,'String', tmp_coor{1}); handles.currentxyz = xyz'; guidata(hObject, handles); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% structure edit %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function CallBack_structureEdit(action, xyz, thisfun, hReg) try handles=guidata(hReg); catch return; end handles.currentxyz = xyz'; guidata(hReg, handles); try [tmp_coor, cellstructure] = cuixuFindStructure(xyz', handles.DB); catch return; end set(handles.structureEdit,'String', tmp_coor{1}); for ii=[5 3 2 6 1 4] if strfind('undefined', cellstructure{ii}) continue; else set(handles.searchContentEdit,'string', trimStructureStr(cellstructure{ii})); return; end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% trim str %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function out = trimStructureStr(str) pos = findstr('(', str); if ~isempty(pos) str(pos-1:end)=[]; end out = str; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% cluster size threshold edit %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function CallBack_clusterSizeThresholdEdit(hObject, eventdata) handles = guidata(hObject); tmp = str2double(get(hObject, 'String')); if isnan(tmp) | tmp<0 errordlg('Please input a valid number.','error'); try set(hObject, 'String', handles.clusterSizeThreshold); catch set(hObject, 'String', '5'); end return end handles.clusterSizeThreshold=tmp; guidata(hObject, handles); CallBack_allIntensityRadio(hObject, eventdata, 'c'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% save image push button %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function CallBack_saveImagePush(hObject, eventdata, thisfilename, isMask) handles = guidata(hObject); if exist('thisfilename') if ~strcmp(deblank(thisfilename), '') if isfield(handles,'imageFileName') if ~isempty(handles.imageFileName) mni2mask(cell2mat(handles.currentDisplayMNI'), thisfilename, cell2mat(handles.currentDisplayIntensity), handles.M{1}, handles.DIM{1}, handles.imageFileName{1}); return; end end mni2mask(cell2mat(handles.currentDisplayMNI'), thisfilename, cell2mat(handles.currentDisplayIntensity), handles.M{1}, handles.DIM{1}); return; end end [filename, pathname] = uiputfile('*.img', 'Save image file as', get(handles.saveImageFileEdit, 'string')); if isequal(filename,0) | isequal(pathname,0) return else thisfilename = fullfile(pathname, filename); end if isfield(handles,'imageFileName') if ~isempty(handles.imageFileName{1}) mni2mask(cell2mat(handles.currentDisplayMNI'), thisfilename, cell2mat(handles.currentDisplayIntensity'), handles.M{1}, handles.DIM{1}, handles.imageFileName{1}, isMask); return; end end mni2mask(cell2mat(handles.currentDisplayMNI'), thisfilename, cell2mat(handles.currentDisplayIntensity), handles.M{1}, handles.DIM{1}, '', isMask); return; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% save image edit %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function CallBack_saveImageFileEdit(hObject, eventdata) handles = guidata(hObject); CallBack_saveImagePush(handles.saveImagePush, eventdata, get(hObject,'string')); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% save result push %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function CallBack_saveResultPSPush(hObject, eventdata, thisfilename) handles = guidata(hObject); if exist('thisfilename') if ~strcmp(deblank(thisfilename), '') spm_print(handles.figure); if strcmp(handles.system, 'linux') system(['ps2pdf spm2.ps']); system(['mv spm2.ps ' thisfilename]); [p,f,ext]=fileparts(thisfilename); system(['mv spm2.pdf ' fullfile(p,f) '.pdf']); elseif strcmp(handles.system, 'windows') system(['move spm2.ps ' '"' thisfilename '"']); end return; end end [filename, pathname] = uiputfile('*.ps', 'Save result as', get(handles.saveResultPSEdit, 'string')); if isequal(filename,0) | isequal(pathname,0) return else thisfilename = fullfile(pathname, filename); end % print H = findobj(get(handles.figure,'Children'),'flat','Type','axes'); un = cellstr(get(H,'Units')); pos = get(H,'position'); index = []; for ii=1:length(H) if findstr('pixels', un{ii}) continue; end if pos{ii}(1)>0.4 & pos{ii}(2) > 0.5 set(H(ii),'position',[pos{ii}(1), pos{ii}(2), pos{ii}(3)*3/4, pos{ii}(4)]); index = [index ii]; end end spm_print(handles.figure); if strcmp(handles.system, 'linux') system(['ps2pdf spm2.ps']); system(['mv spm2.ps ' thisfilename]); [p,f,ext]=fileparts(thisfilename); system(['mv spm2.pdf ' fullfile(p,f) '.pdf']); elseif strcmp(handles.system, 'windows') system(['move spm2.ps ' '"' thisfilename '"']); end % set the position back set(H(index), {'position'}, pos(index)); % printstr = ['print -dpsc2 -painters -noui ' '''' thisfilename '''']; % try % orient portrait % eval(printstr); % printsuccess = 1; % catch % errordlg('Print to ps file failed', 'print error'); % printsuccess = 0; % end %set(H,{'Units'},un); % if strcmp(handles.system, 'linux') & printsuccess == 1 % system(['ps2pdf ' '''' thisfilename '''']); % end return; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% save result edit %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function CallBack_saveResultPSEdit(hObject, eventdata) handles = guidata(hObject); CallBack_saveResultPSPush(hObject, eventdata, get(handles.saveResultPSEdit,'string')); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% select a cluster %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function CallBack_selectThisClusterPush(hObject, eventdata) handles = guidata(hObject); try xyz = handles.currentxyz'; catch xyz = spm_XYZreg('GetCoords',handles.hReg); end try handles.selectedCluster = [handles.selectedCluster; xyz']; catch handles.selectedCluster = xyz'; end set(handles.figure,'currentaxes', handles.glassViewAxes); xrange = xlim; yrange = ylim; try delete(handles.hGlassText) end %handles.hGlassText = text(xrange(1)+diff(xrange)*0.6, yrange(1)+diff(yrange)*0.9, [num2str(size(handles.selectedCluster,1)) ' clusters selected']); set(handles.infoTextBox, 'string', [num2str(size(handles.selectedCluster,1)) ' clusters selected']); guidata(hObject, handles); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% unselect a cluster %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function CallBack_clearSelectedClusterPush(hObject, eventdata) handles = guidata(hObject); try handles = rmfield(handles,'selectedCluster'); end set(handles.figure,'currentaxes', handles.glassViewAxes); xrange = xlim; yrange = ylim; try %delete(handles.hGlassText) set(handles.infoTextBox, 'string', ['No clusters selected']); end guidata(hObject, handles); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% pick a cluster %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%