📄 affinetransformation.m
字号:
function varargout = AffineTrnasformation(varargin)
% AFFINETRNASFORMATION M-file for AffineTrnasformation.fig
% Affine_Transf computes and applies the geometric affine transformation to a 2-D image.
%
% The program main functions are:
% - Load Image: Load the image to be transformed.
% - Transform Image: Computes the transformation matrix from the transformation parameters specified by the user, then it applies the transformation to the loaded image.
% - Save Image: Save the transformed image.
% - Quit: Exit the program.
% The transformation parameters are specified by the user by editing the
% values of the rotation, scale (x and y), and shear (x and y). The
% translation is not icluded because it can be easily (normalized or) removed from image by
% subtracting the shape cetroid.
%
% The affine matrix and the transformation are computed using Matlab Image Processing Toolbox
% functions: maketform and imtransform, so this program is only demonstrates the computation and the applying of these functions to a 2-D image.
%
% Version 1.0% Copyright Feb 2003, Ibrahim El Rube
% ielrube@yahoo.com
% Begin initialization code - DO NOT EDIT
global gg gc;
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @AffineTrnasformation_OpeningFcn, ...
'gui_OutputFcn', @AffineTrnasformation_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 AffineTrnasformation is made visible.
function AffineTrnasformation_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 AffineTrnasformation (see VARARGIN)
% Choose default command line output for AffineTrnasformation
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes AffineTrnasformation wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = AffineTrnasformation_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)
global gg
% Get default command line output from handles structure
varargout{1} = handles.output;
gg=2;% --- Executes on button press in Load_image.function Load_image_Callback(hObject, eventdata, handles)% hObject handle to Load_image (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global gg gc;
h=guidata(gcbo);
set(h.message_text,'String',''); % Clear Messages
gg=gg+2;
h.image_filename=1;
h.image_pathname=1;
[filename, pathname] = uigetfile( ...
{'*.bmp;*.tif;*.jpg;*.pcx;*.png;*.hdf;*.xwd;*.ras;*.pbm;*.pgm;*.ppm;*.pnm', 'All MATLAB SUPPORTED IMAGE Files (*.bmp,*.tif,*.jpg,*.pcx,*.png,*.hdf,*.xwd,*.ras,*.pbm,.pgm,*.ppm,*.pnm)'} ...
,'Pick a file'); % Load Image file and path names
if filename~=0
gg=1;
h.gg=1;
h.image_filename=filename; % Image file name
h.image_pathname=pathname; % Image path name
set(h.Showaxes,'visible','off');
axes(h.axes1);
set(h.figure1_title,'Visible','on');
image_1=imread([pathname filename]); % Load Image
imshow(image_1); % Show Loaded Image
h.image_1=image_1;
set(h.axes2,'Visible','off');
axes(h.axes2);
cla;
set(h.figure2_title,'Visible','off');
gc=0;
h.axis12=0;
guidata(gcbo,h);
end% --- Executes during object creation, after setting all properties.function xscale_CreateFcn(hObject, eventdata, handles)% hObject handle to xscale (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.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction xscale_Callback(hObject, eventdata, handles)% hObject handle to xscale (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 xscale as text% str2double(get(hObject,'String')) returns contents of xscale as a
% double% --- Executes during object creation, after setting all properties.function rot_CreateFcn(hObject, eventdata, handles)% hObject handle to rot (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.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction rot_Callback(hObject, eventdata, handles)% hObject handle to rot (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 rot as text% str2double(get(hObject,'String')) returns contents of rot as a double% --- Executes during object creation, after setting all properties.function xshear_CreateFcn(hObject, eventdata, handles)% hObject handle to xshear (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.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction xshear_Callback(hObject, eventdata, handles)% hObject handle to xshear (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 xshear as text% str2double(get(hObject,'String')) returns contents of xshear as a double% --- Executes during object creation, after setting all properties.function xtrans_CreateFcn(hObject, eventdata, handles)% hObject handle to xtrans (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.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction xtrans_Callback(hObject, eventdata, handles)% hObject handle to xtrans (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 xtrans as text% str2double(get(hObject,'String')) returns contents of xtrans as a double% --- Executes on button press in deg.function deg_Callback(hObject, eventdata, handles)% hObject handle to deg (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 deg
h=guidata(gcbo);
%set(h.rad,'Value',0);
ch=get(hObject,'Value');
switch ch
case 0
set(h.rad,'Value',1)
case 1
set(h.rad,'Value',0)
endguidata(gcbo,h);% --- Executes on button press in rad.function rad_Callback(hObject, eventdata, handles)% hObject handle to rad (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 radh=guidata(gcbo);
%set(h.rad,'Value',0);
ch=get(hObject,'Value');
switch ch
case 0
set(h.deg,'Value',1)
case 1
set(h.deg,'Value',0)
end
guidata(gcbo,h);% --- Executes on button press in bshear.function bshear_Callback(hObject, eventdata, handles)% hObject handle to bshear (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 bshear% --- Executes on button press in checkbox2.function checkbox2_Callback(hObject, eventdata, handles)% hObject handle to checkbox2 (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 checkbox2% --- Executes during object creation, after setting all properties.function ytrans_CreateFcn(hObject, eventdata, handles)% hObject handle to ytrans (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -