1 简介
图像拼接技术是数字图像处理邻域的一个研究热点.近年来,随着技术的成熟,图像拼接技术被很好的应用到了机器人导航,无人平台战场监控,航拍图像处理等多个领域.基于特征的图像配准与拼接技术配准结果准确拼接效果良好且不易受光照,旋转等因素的影响是当前图像配准与拼接领域研究的热点.
2 部分代码
function varargout = ImageRegistration(varargin)
% IMAGEREGISTRATION MATLAB code for ImageRegistration.fig
% IMAGEREGISTRATION, by itself, creates a new IMAGEREGISTRATION or raises the existing
% singleton*.
%
% H = IMAGEREGISTRATION returns the handle to a new IMAGEREGISTRATION or the handle to
% the existing singleton*.
%
% IMAGEREGISTRATION('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in IMAGEREGISTRATION.M with the given input arguments.
%
% IMAGEREGISTRATION('Property','Value',...) creates a new IMAGEREGISTRATION or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ImageRegistration_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ImageRegistration_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
%
% Edit the above text to modify the response to help ImageRegistration
%
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ImageRegistration_OpeningFcn, ...
'gui_OutputFcn', @ImageRegistration_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
addpath(pwd);
% --- Executes just before ImageRegistration is made visible.
function ImageRegistration_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 ImageRegistration (see VARARGIN)5
% Choose default command line output for ImageRegistration
handles.output = hObject;
% 消除axes坐标轴
set(handles.axes1,'Xtick',[],'Ytick',[]);
set(handles.axes1,'Xcolor',[1 1 1],'Ycolor',[1 1 1]);
set(handles.axes2,'Xtick',[],'Ytick',[]);
set(handles.axes2,'Xcolor',[1 1 1],'Ycolor',[1 1 1]);
set(handles.axes3,'Xtick',[],'Ytick',[]);
set(handles.axes3,'Xcolor',[1 1 1],'Ycolor',[1 1 1]);
set(handles.axes4,'Xtick',[],'Ytick',[]);
set(handles.axes4,'Xcolor',[1 1 1],'Ycolor',[1 1 1]);
set(handles.axes5,'Xtick',[],'Ytick',[]);
set(handles.axes5,'Xcolor',[1 1 1],'Ycolor',[1 1 1]);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ImageRegistration wait for user response (see UIRESUME)
% uiwait(handles.figure1);
end
diff1 = im2bw(diff1,graythresh(diff1));
figure,imshow(diff1)
% 标出变化区域
axes(handles.axes5)
imshow(BaseImage)
hold on;
[L,num] = bwlabel(diff1,4);
for i=1:num
[m{i},n{i}] = find(L == i);
if length(m{i})*length(n{i}) > 20 % 判断变化区域面积
height = max(m{i}) - min(m{i});
width = max(n{i}) - min(n{i});
if height <= 0 || width <= 0 % 变化区域宽或高太小都舍弃
continue;
end
rectangle('position',[min(n{i}) min(m{i}) width height],'curvature',[1,1],'edgecolor','r');
hold on;
end
end
hold off;
% % 显示阈值处理过后的差分结果
% axes(handles.axes5)
% imshow(diff1);
global matchTable;
% global img3;
% global loc1;
% global loc2;
% global des1;
% Show a figure with lines joining the accepted matches.
%展示一张用线连接两图
% axes(handles.axes4)
% % figure('Position', [100 100 size(img3,2) size(img3,1)]);
% colormap('gray');
% imagesc(img3);
% hold on;
% cols1 = size(BaseImage,2);
% for i = 1: size(des1,1)
% if (matchTable(i) > 0)
% line([loc1(i,2) loc2(matchTable(i),2)+cols1], ...
% [loc1(i,1) loc2(matchTable(i),1)], 'Color', 'c');
% end
% end
% hold off;
% set(handles.axes4,'Xtick',[],'Ytick',[]);
% set(handles.axes4,'Xcolor',[1 1 1],'Ycolor',[1 1 1]);
num = sum(matchTable > 0);
% 显示配准参数
Matchkey=sprintf('Match Keypoints=[%d]',num);
set(handles.text6,'string',Matchkey);
set(handles.text7,'string',ElapsedTime);
% --------------------------------------------------------------------
function uipushtool1_ClickedCallback(hObject, eventdata, handles)
% hObject handle to uipushtool1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename,pathname] = uiputfile({'*.jpg','JPEG(*.jpg)';...
'*.bmp','Bitmap(*.bmp)';...
'*.gif','GIF(*.gif)';...
'*.*', 'All Files (*.*)'},...
'保存图片','Untitled');
if filename==0
return;
else
imname = fullfile(pathname,filename);
pix=getframe(handles.axes5);
imwrite(pix.cdata,imname);
end
3 仿真结果
4 参考文献
[1]袁杰. 基于SIFT的图像配准与拼接技术研究[D]. 南京理工大学.
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机、雷达通信、无线传感器等多种领域的Matlab仿真,相关matlab代码问题可私信交流。
部分理论引用网络文献,若有侵权联系博主删除。