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

📄 rotatetool.m

📁 Rotation tool, totates a single image contained in HANDLE.HANDLE can be a handle to figure, axes, or
💻 M
📖 第 1 页 / 共 2 页
字号:
% ----------------------------------------------------------------------------function push_cancel_Callback(hObject, eventdata, handles)if isequal(get(handles.figure1, 'waitstatus'), 'waiting')    % The GUI is still in UIWAIT, us UIRESUME    handles.cancel = 1;      % User gave up, return nothing    guidata(hObject, handles);    uiresume(handles.figure1);else    % The GUI is no longer waiting, just close it    delete(handles.figure1)end% ----------------------------------------------------------------------------function push_apply_Callback(hObject, eventdata, handles)    switch get(handles.popup_interpmenu,'Value')        case 1,     interpmethod = 'nearest';        case 2,     interpmethod = 'bilinear';        case 3,     interpmethod = 'bicubic';    end    if (~isempty(handles.hOrigFigure))  % Original data is in a figure        A = get(handles.hOrigImage,'CData');        if (handles.do_flipLR),     A = flipdim(A,2);   end        if (handles.do_flipUD),     A = flipdim(A,1);   end        rotCdata = imrotate(A,-handles.angle,interpmethod,handles.bbox);        set(handles.hOrigImage,'CData',rotCdata);    else        if (~isempty(handles.OrigGrd))            A = handles.OrigGrd;            if (handles.do_flipLR),     A = flipdim(A,2);   end            if (handles.do_flipUD),     A = flipdim(A,1);   end            rotCdata = imrotate(A,-handles.angle,interpmethod,'loose');        else            A = handles.OrigImage;            if (handles.do_flipLR),     A = flipdim(A,2);   end            if (handles.do_flipUD),     A = flipdim(A,1);   end            rotCdata = imrotate(A,-handles.angle,interpmethod,handles.bbox);        end        handles.output_grd = rotCdata;        if (handles.out_header)            nx = size(rotCdata,2);      ny = size(rotCdata,1);            x_inc = (handles.in_hdr(2) - handles.in_hdr(1)) / (nx - ~handles.in_hdr(7));            y_inc = (handles.in_hdr(4) - handles.in_hdr(3)) / (ny - ~handles.in_hdr(7));            handles.out_header = [handles.in_hdr(1:4) double(min(rotCdata(:))) ...                double(max(rotCdata(:))) handles.in_hdr(7) x_inc y_inc];        end        guidata(handles.figure1,handles)    end    if isequal(get(handles.figure1, 'waitstatus'), 'waiting')        % The GUI is still in UIWAIT, let us UIRESUME        uiresume(handles.figure1);    else        delete(handles.figure1)    end%=============================function updateAngleInfo(handles,angle)    % used for the +/- 90 rotation callbacks, which rotate current    % preview image in increments of +/- 90 degrees    updatedAngle = checkAngle(angle + handles.angle);    handles.angle = updatedAngle;    set(handles.edit_angRot,'String',num2str(updatedAngle));    set(handles.slider,'Value',updatedAngle);    guidata(handles.figure1,handles)%=======================================function updatedAngle = checkAngle(angle)    % used to wrap rotation angle between +/- 180    updatedAngle = angle;    if ~(abs(angle) <= 180) % wrap angle if necessary        r = rem(angle,360);        if (abs(r) <= 180),     updatedAngle = r;        else                    updatedAngle = r-sign(r)*360;        end    end%==============================================function [leftpos,bottompos] = calcPosition(handles,w,h)    % calculate position values to center axes(image) in preview area.    % Rotation will look like a pin wheel.    PanelPos = handles.frame_axesPos;    leftpos   = (PanelPos(3) - w)/2;    bottompos = (PanelPos(4) - h)/2;%==============================================================function [hout] = displayPreviewImage(handles,newCdata,cmap)    % Create a preview image from original image.    [h,w,k] = size(newCdata);    xdata = [1 w];    ydata = [1 h];    if (~isempty(handles.hOrigImage))        clim = get(get(handles.hOrigImage,'Parent'),'Clim');        cdatamapping = get(handles.hOrigImage,'CdataMapping');        cmap = get(handles.hOrigFigure,'Colormap');             % Those will not overwrite the input because        y_dir = get(get(handles.hOrigImage,'Parent'),'YDir');   % cmap is not know yet (that is: cmap = [])        hout = image(xdata,ydata,newCdata, ...            'BusyAction', 'cancel', 'CDataMapping', cdatamapping, ...            'Parent', handles.axes1, 'Interruptible', 'off');    else        hout = image(xdata,ydata,newCdata, 'BusyAction', 'cancel', ...            'Parent', handles.axes1, 'Interruptible', 'off');        clim = [];      y_dir = 'normal';    end    % Set axes and figure properties if necessary to display the image object correctly.    axesPosition = get(handles.axes1,'Position');    set(handles.axes1, 'Xlim',[1 w], 'Ylim',[1 h], 'Ydir', y_dir, ...        'Position',[axesPosition(1:2) w h], 'Visible','off');    if (~isempty(cmap)),    set(handles.figure1, 'Colormap', cmap);   end    if (~isempty(clim)),    set(handles.axes1, 'CLim', clim);   end    isIndexedUint16Image = strcmpi(get(hout,'CDataMapping'),'direct') && size(cmap,1) > 256;    if (isIndexedUint16Image && ispc)        set(handles.figure1,'Renderer','Zbuffer');    end        %=========================function updateImage(handles)    % updateImage performs the rotates preview image    handles = guidata(handles.figure1);    interpmethod = 'nearest';                       % changes to the interp method will    switch get(handles.popup_bboxmenu,'Value')      % not be noticeable in the preview image.        case 1,     outsize = 'loose';        case 2,     outsize = 'crop';    end    %assuming cw rotation is positive (need to use -angle because    %IMROTATE assumes cw rotation is negative)    rotCdata = imrotate(handles.previewImage,-handles.angle,interpmethod,outsize);    [h,w,k] = size(rotCdata);    [left,bottom] = calcPosition(handles,w,h);    left = left + handles.frame_axesPos(1);    bottom = bottom + handles.frame_axesPos(2);    try        single(1)/1;        set(handles.axes1, 'Xlim',[1 w], 'Ylim',[1 h], 'Position',[left bottom w h])   % This srews in R13    catch        set(handles.axes1, 'Position',[left bottom w h])                               % And this screws on >= R14    end    set(handles.himage,'Cdata',rotCdata)    %Store rotation specific information needed to rotate the original    %image after the rotate GUI is closed or the user hits apply.    handles.bbox = outsize;    guidata(handles.figure1,handles)% ----------------------------------------------------------------------------function figure1_CloseRequestFcn(hObject, eventdata, handles)handles = guidata(handles.figure1);push_cancel_Callback(hObject, eventdata, handles)% ----------------------------------------------------------------------------function figure1_KeyPressFcn(hObject, eventdata, handles)if isequal(get(hObject,'CurrentKey'),'escape')    handles = guidata(handles.figure1);    push_cancel_Callback(hObject, eventdata, handles)end% ----------------------------------------------------------------------------% --- Creates and returns a handle to the GUI figure. function rotatetool_LayoutFcn(h1,handles)set(h1,...'PaperUnits',get(0,'defaultfigurePaperUnits'),...'CloseRequestFcn',{@figure1_CloseRequestFcn,handles},...'Color',get(0,'factoryUicontrolBackgroundColor'),...'DoubleBuffer','on',...'KeyPressFcn',{@figure1_KeyPressFcn,handles},...'MenuBar','none',...'Name','rotatetool',...'NumberTitle','off',...'Position',[520 418 451 375],...'RendererMode','manual',...'Resize','off',...'HandleVisibility','callback',...'Tag','figure1');uicontrol('Parent',h1,'Position',[134 40 314 108],'Style','frame','Tag','frame3');uicontrol('Parent',h1,'Position',[2 4 446 35],'Style','frame','Tag','frame2');uicontrol('Parent',h1,'Position',[2 40 131 332],'Style','frame','Tag','frame1');uicontrol('Parent',h1,...'Callback',{@rotatetool_uicallback,h1,'push_cw90_Callback'},...'Position',[7 339 120 20],...'String',['Clockwise 90' char(186)],...'Tag','push_cw90');axes('Parent',h1,...'Units','pixels',...'CameraPosition',[0.5 0.5 9.16025403784439],...'CameraPositionMode',get(0,'defaultaxesCameraPositionMode'),...'Color',get(0,'defaultaxesColor'),...'Position',[135 150 311 221],...'Tag','axes1');uicontrol('Parent',h1,...'Callback',{@rotatetool_uicallback,h1,'push_ccw90_Callback'},...'Position',[7 309 120 20],...'String',['Counterclockwise 90' char(186)],...'Tag','push_ccw90');uicontrol('Parent',h1,...'Callback',{@rotatetool_uicallback,h1,'push_flipLR_Callback'},...'Position',[7 279 120 20],...'String','Flip Left/Right',...'Tag','push_flipLR');uicontrol('Parent',h1,...'Callback',{@rotatetool_uicallback,h1,'push_flipUD_Callback'},...'Position',[7 249 120 20],...'String','Flip Up/Down',...'Tag','push_flipUD');uicontrol('Parent',h1,...'Callback',{@rotatetool_uicallback,h1,'slider_Callback'},...'Max',180,...'Min',-180,...'SliderStep',[1/360 5/360],...'Position',[150 122 181 18],...'Style','slider',...'Tag','slider');uicontrol('Parent',h1,...'BackgroundColor',[1 1 1],...'Callback',{@rotatetool_uicallback,h1,'edit_angRot_Callback'},...'Position',[350 120 71 21],...'String','0',...'Style','edit',...'Tag','edit_angRot');uicontrol('Parent',h1,...'BackgroundColor',[1 1 1],...'Callback',{@rotatetool_uicallback,h1,'popup_bboxmenu_Callback'},...'Position',[210 79 231 22],...'String',{'Expanded to Fit Rotated Input Image'; 'Same as Input Image'},...'Style','popupmenu', 'Value',1,...'Tag','popup_bboxmenu');uicontrol('Parent',h1,...'BackgroundColor',[1 1 1],...'Callback',{@rotatetool_uicallback,h1,'popup_interpmenu_Callback'},...'Position',[210 50 121 22],...'String',{'Nearest-neighbor'; 'Bilinear'; 'Bicubic'},...'Style','popupmenu', 'Value',1,...'Tag','popup_interpmenu');uicontrol('Parent',h1,'Position',[144 83 65 15],...'String','Output Size:','Style','text','Tag','text1');uicontrol('Parent',h1,'Position',[144 54 65 15],...'String','Interpolation:','Style','text','Tag','text2');uicontrol('Parent',h1,...'Callback',{@rotatetool_uicallback,h1,'push_cancel_Callback'},...'Position',[262 9 60 25],...'String','Cancel',...'Tag','push_cancel');uicontrol('Parent',h1,...'Callback',{@rotatetool_uicallback,h1,'push_apply_Callback'},...'Position',[341 9 100 25],...'String','Apply n Return',...'TooltipString','Apply the rotation to original data and quit',...'Tag','push_apply');uicontrol('Parent',h1,...'HorizontalAlignment','left',...'Position',[147 106 30 15],...'String',['-180' char(186)],...'Style','text',...'Tag','text3');uicontrol('Parent',h1,...'HorizontalAlignment','left',...'Position',[309 106 30 15],...'String',['180' char(186)],...'Style','text',...'Tag','text4');uicontrol('Parent',h1,...'HorizontalAlignment','left',...'Position',[241 106 10 15],...'String',['0' char(186)],...'Style','text',...'Tag','text5');uicontrol('Parent',h1,'Position',[134 149 314 223],...'Style','frame','Tag','frame_axes');function rotatetool_uicallback(hObject, eventdata, h1, callback_name)% This function is executed by the callback and than the handles is allways updated.feval(callback_name,hObject,[],guidata(h1));

⌨️ 快捷键说明

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