www.gusucode.com > Matlab基于金字塔结构的图像处理 GUI界面源码程序 > ImgaeMatch.m

    function varargout = ImgaeMatch(varargin)
% IMGAEMATCH M-file for ImgaeMatch.fig
%      IMGAEMATCH, by itself, creates a new IMGAEMATCH or raises the existing
%      singleton*.
%
%      H = IMGAEMATCH returns the handle to a new IMGAEMATCH or the handle to
%      the existing singleton*.
%
%      IMGAEMATCH('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in IMGAEMATCH.M with the given input arguments.
%
%      IMGAEMATCH('Property','Value',...) creates a new IMGAEMATCH or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before ImgaeMatch_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to ImgaeMatch_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 ImgaeMatch

% Last Modified by GUIDE v2.5 06-Mar-2007 16:23:20

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @ImgaeMatch_OpeningFcn, ...
                   'gui_OutputFcn',  @ImgaeMatch_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(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 ImgaeMatch is made visible.
function ImgaeMatch_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 ImgaeMatch (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = ImgaeMatch_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 ImageOpen.
function ImageOpen_Callback(hObject, eventdata, handles)
% hObject    handle to ImageOpen (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
fprintf('请输入源图像\n');
[FileName,PathName] = uigetfile({'*.bmp';'*.jpg';'*.gif';'*.*'},...
     'Select the Source Image');
filename = fullfile(PathName,FileName);
if isequal(FileName,0)
    disp('User selected Cancel');
else
    disp(['User selected ',filename]);
end
img = imread(filename);
handles.img = img;
axes(handles.main)
imshow(img);
set(handles.text2,'String',filename);
guidata(hObject, handles);


fprintf('请输入模板图像\n');
[FileName,PathName] = uigetfile({'*.bmp';'*.jpg';'*.gif';'*.*'},...
     'Select the Template');
filename = fullfile(PathName,FileName);
if isequal(FileName,0)
    disp('User selected Cancel');
else
    disp(['User selected ',filename]);
end
tmp = imread(filename);
handles.tmp = tmp;
axes(handles.mark)
imshow(tmp);
set(handles.text3,'String',filename);
guidata(hObject, handles);


% --- Executes on button press in ImageMatch.
function ImageMatch_Callback(hObject, eventdata, handles)
% hObject    handle to ImageMatch (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
img = handles.img;
tmp = handles.tmp;
[ybegin,xbegin,yend,xend] = PydXcorr(img,tmp,2);
set(handles.text4,'String',ybegin);
set(handles.text5,'String',xbegin);
axes(handles.main)
imshow(img);
hold on;
for i = 1:length(ybegin)
    plot(xbegin(i),ybegin(i):yend(i),'r',...
        xend(i),ybegin(i):yend(i),'r',...
        xbegin(i):xend(i),ybegin(i),'r',...
        xbegin(i):xend(i),yend(i),'r');
end