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

📄 simple_image_rotation_program.m

📁 图像根据角度旋转,可选择角度。 图像根据角度旋转,可选择角度。
💻 M
字号:
% Program to rotate an image by 90, 180 and 270 degrees

function varargout = Image_Rotate(varargin)
% IMAGE_ROTATE M-file for Image_Rotate.fig
%      IMAGE_ROTATE, by itself, creates a new IMAGE_ROTATE or raises the existing
%      singleton*.
%
%      H = IMAGE_ROTATE returns the handle to a new IMAGE_ROTATE or the handle to
%      the existing singleton*.
%
%      IMAGE_ROTATE('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in IMAGE_ROTATE.M with the given input arguments.
%
%      IMAGE_ROTATE('Property','Value',...) creates a new IMAGE_ROTATE or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Image_Rotate_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Image_Rotate_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Image_Rotate

% Last Modified by GUIDE v2.5 13-Jan-2007 10:26:09
% Begin initialization code - DO NOT EDIT

gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Image_Rotate_OpeningFcn, ...
                   'gui_OutputFcn',  @Image_Rotate_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin & isstr(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before Image_Rotate is made visible.
function Image_Rotate_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to Image_Rotate (see VARARGIN)

% Choose default command line output for Image_Rotate
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Image_Rotate wait for user response (see UIRESUME)
% uiwait(handles.figure1);

clear all
clc
axis off
hold off


% --- Outputs from this function are returned to the command line.
function varargout = Image_Rotate_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;

% --- Executes on button press in Browsebutton.
function Browsebutton_Callback(hObject, eventdata, handles)
% hObject    handle to Browsebutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

tic   % Starting Stopwatch Timer
global IMG ORI_IMG
% Loading the Image
[filename, pathname, filterindex]=uigetfile( ...
    {'*.jpg','JPEG File (*.jpg)'; ...
     '*.*','Any Image file (*.*)'}, ...
     'Pick an image file');
var=strcat(pathname,filename);
ORI_IMG=imread(var);
IMG=ORI_IMG;
% Showing the origional image
imshow(IMG);
set(handles.ElpasedTime_edit,'string',toc);   % Displaying elapsed time
set(handles.RotateDegree_edit,'string',0);    % Displaying the angle of rotation


% --- Executes on button press in Rotate90button.
function Rotate90button_Callback(hObject, eventdata, handles)
% hObject    handle to Rotate90button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Rotating image by 90 degrees
tic
global IMG;
image=double(IMG);
s=size(image);
result=zeros(s(2),s(1),s(3)); % Allocating memory for fast execution
for i = 1:s(1)
    j=1:s(2);
    k=s(2)-j+1;
    result(k,i,:)=image(i,j,:); % Computing the new matrix
end
res=uint8(result);
IMG=res;
imshow(IMG); % Displaying the rotated image
set(handles.ElpasedTime_edit,'string',toc);
set(handles.RotateDegree_edit,'string',90);


% --- Executes on button press in Rotate180button.
function Rotate180button_Callback(hObject, eventdata, handles)
% hObject    handle to Rotate180button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Rotating image by 180 degrees
tic
global IMG
image=double(IMG);
s=size(image);
result=zeros(s(1),s(2),s(3));
for i = 1:s(1)
    j = 1:s(2);
    k=s(1)-i+1;
    l=s(2)-j+1;
    result(k,l,:)=image(i,j,:);
end
res=uint8(result);
IMG=res;
imshow(IMG);
set(handles.ElpasedTime_edit,'string',toc);
set(handles.RotateDegree_edit,'string',180);


% --- Executes on button press in Rotate270button.
function Rotate270button_Callback(hObject, eventdata, handles)
% hObject    handle to Rotate270button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Roating the image by 270 degrees
tic
global IMG
image=double(IMG);
s=size(image);
result=zeros(s(2),s(1),s(3));
for i = 1:s(1)
    j = 1:s(2);
    k=s(1)-i+1;
    result(j,k,:)=image(i,j,:);
end
res=uint8(result);
IMG=res;
imshow(IMG);
set(handles.ElpasedTime_edit,'string',toc);
set(handles.RotateDegree_edit,'string',270);


% --- Executes during object creation, after setting all properties.
function ElpasedTime_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to ElpasedTime_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));


function ElpasedTime_edit_Callback(hObject, eventdata, handles)
% hObject    handle to ElpasedTime_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of ElpasedTime_edit as text
%        str2double(get(hObject,'String')) returns contents of ElpasedTime_edit as a double


% --- Executes during object creation, after setting all properties.
function RotateDegree_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to RotateDegree_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.

set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));


function RotateDegree_edit_Callback(hObject, eventdata, handles)
% hObject    handle to RotateDegree_edit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of RotateDegree_edit as text
%        str2double(get(hObject,'String')) returns contents of RotateDegree_edit as a double

% --- Executes on button press in ShowOrigional_checkbox.function ShowOrigional_checkbox_Callback(hObject, eventdata, handles)% hObject    handle to ShowOrigional_checkbox (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hint: get(hObject,'Value') returns toggle state of ShowOrigional_checkbox
global ORI_IMG IMG h
if (get(handles.ShowOrigional_checkbox,'Value') == 0),
    subplot(1,1,1);   % Deleting all subplots present
    imshow(IMG);
else
   subplot(1,2,1), imshow(ORI_IMG);   % Displaying origional image
   subplot(1,2,2), imshow(IMG);   % Displaying the rotated image

end
% --- Executes on button press in Savebutton.function Savebutton_Callback(hObject, eventdata, handles)% hObject    handle to Savebutton (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)global IMG
image=uint8(IMG);
% Saving the rotated image[filename,pathname] = uiputfile( ...
       {'*.jpg', 'JPEG Image File'; ...
        '*.*',   'All Files (*.*)'}, ...
        'Save current image as');
    
var=strcat(pathname,filename,'.jpg');
imwrite(image,var);

⌨️ 快捷键说明

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