📄 grabit.m
字号:
'value' , 0, ... 'backgroundcolor' , handles.bgcolor3, ... 'string' , 'Calibrate'); handles.curTitle = ''; set(get(handles.ImageAxis, 'title'), 'string', ''); handles.curPointer = 'arrow'; set(handles.GrabitGUI, ... 'WindowButtonMotionFcn' , {@pointerFcn, handles, handles.curPointer}); set([handles.LoadImageBtn, ... handles.SaveAs, ... handles.Rename, ... handles.Delete], ... 'enable', 'on'); % calibration was prematurely stopped, so reset all values set(handles.CalibPtsH, 'xdata', NaN, 'ydata', NaN); handles.CalibVals = []; handles.CalibPts = [NaN, NaN, NaN, NaN]; handles.CalibPtsIm = repmat(NaN, 4, 2); set([handles.hXoValue, handles.hXmValue, ... handles.hYoValue, handles.hYmValue], ... 'string', ' NaN'); set(handles.GrabPointsBtn, 'enable', 'off'); set(handles.CoordinateEdit, 'visible', 'off'); % change state to NORMAL handles.state = 'normal'; endendguidata(obj, handles);%--------------------------------------------------------------------------%--------------------------------------------------------------------------% grabPointsFcn%--------------------------------------------------------------------------%--------------------------------------------------------------------------function grabPointsFcn(varargin)% this function is used to extract data points by prompting the user to% select points on the image.obj = varargin{1};handles = guidata(obj);switch get(obj, 'value') case 0 % initiate point grabbing calib = handles.CalibVals; axes(handles.ImageAxis); set(handles.ImageAxis, ... 'xlim', handles.ImLimits(1,:), ... 'ylim', handles.ImLimits(2,:)); set(handles.ImageLine, 'xdata', NaN, 'ydata', NaN); handles.curTitle = {'Grab points by clicking on data points.', ... '<BACKSPACE> or <DEL> to delete previous point. <ENTER> to finish.'}; set(get(handles.ImageAxis, 'title'), ... 'string', handles.curTitle); set(handles.PreviewLine, 'xdata', NaN, 'ydata', NaN); set(handles.PreviewAxis, ... 'xlim', [min([calib.Xo calib.Xm]) max([calib.Xo calib.Xm])], ... 'ylim', [min([calib.Yo calib.Ym]) max([calib.Yo calib.Ym])]); handles.ImDat = []; handles.TrueDat = []; handles.curPointer = 'crosshair'; set(handles.GrabitGUI, ... 'WindowButtonMotionFcn', {@pointerFcn, handles, handles.curPointer}); set(obj, ... 'value' , 1, ... 'string' , 'Grabbing Points (0)', ... 'backgroundcolor' , handles.bgcolor4); set([handles.CalibrateImageBtn, ... handles.LoadImageBtn, ... handles.SaveAs, ... handles.Rename, ... handles.Delete], ... 'enable', 'off'); % change state to GRAB handles.state = 'grab'; case 1 % finish point grabbing set(obj, ... 'value' , 0, ... 'string' , 'Grab Points', ... 'backgroundcolor' , handles.bgcolor1); handles.curTitle = ''; set(get(handles.ImageAxis, 'title'), 'string', ''); handles.curPointer = 'arrow'; set(handles.GrabitGUI, 'WindowButtonMotionFcn', {@pointerFcn, handles, handles.curPointer}); set(handles.CalibrateImageBtn, 'enable', 'inactive'); set([handles.LoadImageBtn, ... handles.SaveAs, ... handles.Rename, ... handles.Delete], ... 'enable', 'on'); if ~isempty(handles.TrueDat) % some points were grabbed varNames = fieldnames(handles.savedVars); varNames{end + 1} = findNextVarNameFcn(varNames); handles.savedVars.(varNames{end}) = handles.TrueDat; assignin('base', varNames{end}, handles.savedVars.(varNames{end})); showAllVarsFcn(handles); end % change to NORMAL state handles.state = 'normal';end guidata(obj, handles);%--------------------------------------------------------------------------%--------------------------------------------------------------------------% showAllVarsFcn%--------------------------------------------------------------------------%--------------------------------------------------------------------------function showAllVarsFcn(handles)% this function shows all data set variables that exist in the GRABIT% workspace in the variable listbox.varNames = fieldnames(handles.savedVars);if isempty(varNames) listboxStr = {''};else for id = 1:length(varNames) [m, n] = size(handles.savedVars.(varNames{id})); listboxStr{id} = sprintf('%s [%dx%d]', varNames{id}, m, n); endendset(handles.VariableList, 'string', listboxStr, 'value', length(listboxStr));%--------------------------------------------------------------------------%--------------------------------------------------------------------------% findNextVarNameFcn%--------------------------------------------------------------------------%--------------------------------------------------------------------------function newVarName = findNextVarNameFcn(varNames)% this helper function determines the next available variable name by% checking the existing variable names in the base workspace and GRABIT% workspace.wsVarNames = evalin('base', 'who');vars = unique([wsVarNames(:); varNames(:)]);idx = 1;while 1 if isempty(strmatch(sprintf('Data%03d', idx), vars, 'exact')) newVarName = sprintf('Data%03d', idx); return; else idx = idx + 1; endend%--------------------------------------------------------------------------%--------------------------------------------------------------------------% zoomBtnFcn%--------------------------------------------------------------------------%--------------------------------------------------------------------------function zoomBtnFcn(varargin)% this function toggles the zoom stateobj = varargin{1};handles = guidata(obj);switch get(obj, 'value') case 0 set(obj, ... 'value' , 1, ... 'backgroundcolor', handles.bgcolor4, ... 'cdata' , handles.zoomIconDown); udata.titlestring = get(get(handles.ImageAxis, 'Title'), 'string'); udata.btnstate = get([handles.LoadImageBtn, ... handles.CalibrateImageBtn, ... handles.GrabPointsBtn, ... handles.VariableList, ... handles.SaveAs, ... handles.Rename, ... handles.Delete],'enable'); udata.imgstate = get(handles.ImageAxis, 'ButtonDownFcn'); udata.handlevisibility = get(handles.ImageAxis, 'handlevisibility'); set(obj, 'userdata', udata); set(get(handles.ImageAxis, 'Title'), 'string', 'Zoom ON'); set([handles.LoadImageBtn, ... handles.CalibrateImageBtn, ... handles.GrabPointsBtn, ... handles.VariableList, ... handles.SaveAs, ... handles.Rename, ... handles.Delete], 'enable', 'off'); set(handles.ImageAxis, 'ButtonDownFcn', ''); zoom('on'); handles.curPointerData.CData = get(handles.GrabitGUI, 'PointerShapeCData'); handles.curPointerData.HotSpot = get(handles.GrabitGUI, 'PointerShapeHotSpot'); set(handles.GrabitGUI, ... 'PointerShapeCData' , handles.zoomPointer, ... 'PointerShapeHotSpot' , handles.zoomPointerHotSpot, ... 'WindowButtonMotionFcn' , {@pointerFcn, handles, 'custom'}, ... 'keypressfcn' , ';'); % this prevents switching to command window % this seems necessary in some versions of Matlab set(handles.ImageAxis, 'handlevisibility', 'on'); case 1 set(obj, ... 'value', 0, ... 'backgroundcolor', handles.bgcolor3, ... 'cdata', handles.zoomIconUp); zoom('off'); %---------------------------------------------------------------------- % If zoom created a compact view window, expand it to fill the whole % axes. %---------------------------------------------------------------------- xl = get(handles.ImageAxis, 'xlim'); xrng = diff(xl); yl = get(handles.ImageAxis, 'ylim'); yrng = diff(yl); if abs(yrng/xrng - handles.imAxRatio) > .01 % wrong axes ratio if yrng/xrng > handles.imAxRatio xrng = yrng / handles.imAxRatio; xl = mean(xl) + [-0.5, 0.5] * xrng; else yrng = xrng * handles.imAxRatio; yl = mean(yl) + [-0.5, 0.5] * yrng; end set(handles.ImageAxis, 'xlim', xl, 'ylim', yl); end %---------------------------------------------------------------------- udata = get(obj, 'userdata'); set(get(handles.ImageAxis, 'Title'), 'string', udata.titlestring); set(handles.ImageAxis, 'handlevisibility', udata.handlevisibility); set([handles.LoadImageBtn, ... handles.CalibrateImageBtn, ... handles.GrabPointsBtn, ... handles.VariableList, ... handles.SaveAs, ... handles.Rename, ... handles.Delete], {'enable'}, udata.btnstate); set(handles.ImageAxis, 'ButtonDownFcn', udata.imgstate); set(handles.GrabitGUI, ... 'PointerShapeCData' , handles.curPointerData.CData, ... 'PointerShapeHotSpot' , handles.curPointerData.HotSpot, ... 'WindowButtonMotionFcn' , {@pointerFcn, handles, handles.curPointer}, ... 'keypressfcn' , @keyPressFcn);endguidata(obj, handles);%--------------------------------------------------------------------------%--------------------------------------------------------------------------% pointerFcn%--------------------------------------------------------------------------%--------------------------------------------------------------------------function pointerFcn(varargin)% this changes the pointer based on whether the cursor is in the image% axes.[handles, ptr] = splitvar(varargin(3:4));pt = get(handles.ImageAxis, 'CurrentPoint');xl = get(handles.ImageAxis, 'xlim');yl = get(handles.ImageAxis, 'ylim');if pt(1,1) > xl(1) && pt(1,1) < xl(2) && pt(1,2) > yl(1) && pt(1,2) < yl(2) set(handles.GrabitGUI, 'pointer', ptr);else set(handles.GrabitGUI, 'pointer', 'arrow');end%--------------------------------------------------------------------------%--------------------------------------------------------------------------% figResize%--------------------------------------------------------------------------%--------------------------------------------------------------------------function figResizeFcn(varargin)% this function makes sure the axis fills the whole axes extentobj = varargin{1};handles = guidata(obj);axis(handles.ImageAxis, 'equal');handles.imAxRatio = diff(get(handles.ImageAxis, 'ylim')) / ... diff(get(handles.ImageAxis, 'xlim'));handles.ImLimits = [get(handles.ImageAxis, 'xlim'); ... get(handles.ImageAxis, 'ylim')];guidata(obj, handles);%--------------------------------------------------------------------------%--------------------------------------------------------------------------% keyPressFcn%--------------------------------------------------------------------------%--------------------------------------------------------------------------function keyPressFcn(varargin)% this is for the keyboard shortcuts. During 'grab' mode, <backspace>% deletes the last point clicked and <return> ends the 'grab' mode.obj = varargin{1};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -