📄 image_rotate.m
字号:
function image_rotate(command)%IMAGE_ROTATE - Rotates the image.%% IMAGE_ROTATE(COMMAND)%% COMMAND - valid commands:%% START - Set up the button frame and initialize% ROTATE - Do the actual rotation% UNDO - Undo the last rotation% RADIO - Set the radio_buttons% SET - Set the edit text% DONE - Keep the last setting%% Claudio Oct. 14 1995%%% Copyright (c) 1995 by Claudio Rivetti and Mark Young% claudio@alice.uoregon.edu, mark@alice.uoregon.edu%global I B_frame Uibgcolor undo_bt prev_radio prev_rotdeg deg_ed deg_txt radio_unit Handlefig if nargin==0 command='START';endif strcmp(upper(command), 'START') % Position variables--------------------------------------------------- pos=get(B_frame, 'Position'); uiwidth=0.12; uithick=0.035; middle=pos(1)+(pos(3)-uiwidth)/2; %--------------------------------------------------------------------- % Positions of buttons ----------------------------------------------------- rbframe_pos = [pos(1)+0.01, pos(2)+.40, pos(3)-0.02 0.35]; sp=rbframe_pos(4)/6; rb1_pos=[rbframe_pos(1)+0.005, rbframe_pos(2)+5*sp, rbframe_pos(3)-0.01, uithick]; rb2_pos=[rbframe_pos(1)+0.005, rbframe_pos(2)+4*sp, rbframe_pos(3)-0.01, uithick]; rb3_pos=[rbframe_pos(1)+0.005, rbframe_pos(2)+3*sp, rbframe_pos(3)-0.01, uithick]; rb4_pos=[rbframe_pos(1)+0.005, rbframe_pos(2)+2*sp, rbframe_pos(3)-0.01, uithick]; rb5_pos=[rbframe_pos(1)+0.005, rbframe_pos(2)+1*sp, rbframe_pos(3)-0.01, uithick]; deg_txt_pos=[rbframe_pos(1), rbframe_pos(2)-0.01, rbframe_pos(3), uithick]; deg_ed_pos=[middle, rbframe_pos(2)-0.01-uithick, uiwidth, uithick]; undo_pos = [middle pos(2)+0.15 uiwidth, uithick]; exec_pos = [middle pos(2)+0.25 uiwidth, uithick]; areatxt_pos = [middle-.01 pos(2)+0.55 uiwidth+.02, uithick]; areaed_pos = [middle pos(2)+0.52 uiwidth, uithick]; %--------------------------------------------------------------------------- if isempty(prev_radio) prev_radio=1; end; if isempty(prev_rotdeg) prev_rotdeg=0; end; % Callbacks for the buttons ------------------ whendone = 'image_rotate(''DONE'');'; exec_cbk = 'image_rotate(''ROTATE'');'; undo_cbk = 'image_rotate(''UNDO'');'; %---------------------------------------------- if ~isimage setviewmode('TOPVIEW'); showimage; end initbuttons('Image Rotation', 'Done', whendone); radio_unit=zeros(5,1); radio_unit_callback = 'image_rotate(''RADIO'');'; radio_unit(1) = uicontrol(Handlefig, 'Style', 'radio',... 'String', '+90 degree',... 'Units', 'Normalized',... 'Position', rb1_pos,... 'HorizontalAlignment', 'left',... 'BackgroundColor', Uibgcolor,... 'UserData', 90,... 'CallBack', radio_unit_callback,... 'Value', 0); radio_unit(2) = uicontrol(Handlefig, 'Style', 'radio',... 'String', '-90 degree',... 'Units', 'Normalized',... 'Position', rb2_pos,... 'HorizontalAlignment', 'left',... 'BackgroundColor', Uibgcolor,... 'UserData', (-90),... 'CallBack', radio_unit_callback,... 'Value', 0); radio_unit(3) = uicontrol(Handlefig, 'Style', 'radio',... 'String', '+180 degree',... 'Units', 'Normalized',... 'Position', rb3_pos,... 'HorizontalAlignment', 'left',... 'BackgroundColor', Uibgcolor,... 'UserData', 180,... 'CallBack', radio_unit_callback,... 'Value', 0); radio_unit(4) = uicontrol(Handlefig, 'Style', 'radio',... 'String', '-180 degree',... 'Units', 'Normalized',... 'Position', rb4_pos,... 'HorizontalAlignment', 'left',... 'BackgroundColor', Uibgcolor,... 'UserData', (-180),... 'CallBack', radio_unit_callback,... 'Value', 0); radio_unit(5) = uicontrol(Handlefig, 'Style', 'radio',... 'String', 'Other...',... 'Units', 'Normalized',... 'Position', rb5_pos,... 'HorizontalAlignment', 'left',... 'BackgroundColor', Uibgcolor,... 'UserData', prev_rotdeg,... 'CallBack', radio_unit_callback,... 'Value', 0); set(radio_unit(prev_radio), 'value', 1); deg_txt=uicontrol(Handlefig, 'Style', 'text',... 'String', 'Angle (deg)',... 'Units', 'normalized',... 'Position', deg_txt_pos,... 'BackgroundColor', Uibgcolor,... 'Visible', onoff(prev_radio==5),... 'HorizontalAlignment', 'center'); deg_ed = uicontrol(Handlefig, 'Style', 'edit',... 'String', num2str(prev_rotdeg),... 'Units', 'normalized',... 'Position', deg_ed_pos,... 'Visible', onoff(prev_radio==5),... 'Value', prev_rotdeg,... 'HorizontalAlignment', 'center',... 'CallBack', 'image_rotate(''SET'');'); uicontrol(Handlefig,'Style','push',... 'String', 'Execute',... 'Units', 'normalized', ... 'Position', exec_pos,... 'CallBack',exec_cbk); undo_bt=uicontrol(Handlefig,'Style','push',... 'String','Undo',... 'Enable', 'off',... 'Units', 'normalized', ... 'Position', undo_pos,... 'CallBack',undo_cbk);end %STARTif strcmp(upper(command), 'ROTATE') f=watchon; statusbar('Image Rotation in progress...'); for i=1:5 r=[r;get(radio_unit(i), 'value')]; end r=find(r==1); deg=get(radio_unit(r), 'UserData'); r=deg/90; if deg==0 | deg==360 | deg==-360 return; elseif r==round(r) setimage(rot90(I, r)); else setimage(imrotate(I, deg, 'bicubic', 'crop')); end clearstatusbar; set(undo_bt, 'Enable', 'on'); watchoff(f);end %ROTATEif strcmp(upper(command), 'RADIO') set(radio_unit(find(radio_unit ~= gco)), 'value', 0); set(gco, 'value', 1); set(deg_ed, 'Visible', onoff(gco==radio_unit(5))); set(deg_txt, 'Visible', onoff(gco==radio_unit(5))); image_rotate('DONE'); end %RADIOif strcmp(upper(command), 'SET') editstr2value(deg_ed, -360, +360); set(radio_unit(5), 'UserData', get(deg_ed, 'value')); image_rotate('DONE');end %SETif strcmp(upper(command), 'DONE') prev_rotdeg=get(radio_unit(5), 'UserData'); for i=1:5 r=[r;get(radio_unit(i), 'value')]; end prev_radio=find(r==1);end %DONEif strcmp(upper(command), 'UNDO') undo; setclipboard([]); set(undo_bt, 'Enable', 'off');end %UNDOreturn
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -