图像配准基于互相关图像配准matlab源码含GUI

Posted Matlab咨询QQ1575304183

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了图像配准基于互相关图像配准matlab源码含GUI相关的知识,希望对你有一定的参考价值。

一、简介

在这里我想探讨一下“互相关”中的一些概念。正如卷积有线性卷积(linear convolution)和循环卷积(circular convolution)之分;互相关也有线性互相关(linear cross-correlation)和循环互相关(circular cross-correlation)。线性互相关和循环互相关的基本公式是一致的,不同之处在于如何处理边界数据。其本质的不同在于它们对原始数据的看法不同。通过这篇文章,我想整理一下相关概念,并给出示例。

1 线性相关(Linear Cross-Correlation)的定义和计算
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
用一个实际的应用例子来验证一下吧。如图3的第一个子图表示雷达声纳发射了一个探测信号。经过一段时间之后,收到了如图3的第二个子图所示的回波(带有一定的噪声)。此时我们关注的是如何确定回波中从何时开始是对探测信号的响应,以便计算目标距雷达的距离,这就需要用到线性互相关。在第三个子图中的‘Valid’曲线即是有效互相关数据,其中清晰地呈现出两处与探测信号相似的回波的位置。
在这里插入图片描述
线性互相关中,还有一些概念值得注意:

1 补零。由线性相关的计算式不难发现,为了计算出个完整的相关系数序列(包含那些“无效数据”在内的所有结果),需要用到一些“不存在”的点。这就需要人为地对这些值进行补充,在线性相关的计算中,对这些超出原始数据储存的区域取值为零。
2 末端效应。由图1可以发现,一头一尾的个互相关数据并没有完全“嵌入”两个原始数组的全部信息,它们或多或少地受到了人为补零的影响。因此一般认为这些数据是不可用的。
3 计算模式的选择。这个问题其实是由问题二衍生而来的,就Python语言中的函数而言,至少有两个可以直接计算线性相关:
在这里插入图片描述
2 循环互相关(Circular Cross-Correlation)的定义和计算
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

二、源代码

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

% Last Modified by GUIDE v2.5 20-Apr-2014 10:31:06

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @xiangguan_OpeningFcn, ...
                   'gui_OutputFcn',  @xiangguan_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 xiangguan is made visible.
function xiangguan_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 xiangguan (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = xiangguan_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 first_picture.
function first_picture_Callback(hObject, eventdata, handles)
% hObject    handle to first_picture (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
subplot(3,3,2)
[filename,pathname]=uigetfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...
    '*.*','All Files' },'open');    %打开路径下要检索的图像
if isequal([filename,pathname],[0,0])
    return
else
    %读取图片
    pic = fullfile(pathname,filename);
   global onion;
   onion = imread(pic);
     imshow(onion); 
end

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

subplot(3,3,3)
[filename,pathname]=uigetfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...
    '*.*','All Files' },'open');    %打开路径下要检索的图像
if isequal([filename,pathname],[0,0])
    return
else
    %读取图片
    pict = fullfile(pathname,filename);
   global peppers;
   peppers = imread(pict);
     imshow(peppers); 
end

% --- Executes on button press in correlation.
function correlation_Callback(hObject, eventdata, handles)
% hObject    handle to correlation (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
subplot(3,3,5)
global onion;
global peppers;
% non-interactively
rect_onion = [111 33 65 58];
rect_peppers = [163 47 143 151];
sub_onion = imcrop(onion,rect_onion);
sub_peppers = imcrop(peppers,rect_peppers);
c = normxcorr2(sub_onion(:,:,1),sub_peppers(:,:,1));
 surf(c), shading flat

% --- Executes on button press in overlay.
function overlay_Callback(hObject, eventdata, handles)
% hObject    handle to overlay (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
subplot(3,3,6)
global onion;
global peppers;
% non-interactively
rect_onion = [111 33 65 58];
rect_peppers = [163 47 143 151];
sub_onion = imcrop(onion,rect_onion);
sub_peppers = imcrop(peppers,rect_peppers);
c = normxcorr2(sub_onion(:,:,1),sub_peppers(:,:,1));
 
 % offset found by correlation
[max_c, imax] = max(abs(c(:)));
[ypeak, xpeak] = ind2sub(size(c),imax(1));
corr_offset = [(xpeak-size(sub_onion,2)) 
               (ypeak-size(sub_onion,1))];
% relative offset of position of subimages
rect_offset = [(rect_peppers(1)-rect_onion(1)) 
               (rect_peppers(2)-rect_onion(2))];
% total offset
offset = corr_offset + rect_offset;
xoffset = offset(1);
yoffset = offset(2);
xbegin = round(xoffset+1);
xend   = round(xoffset+ size(onion,2));
ybegin = round(yoffset+1);
yend   = round(yoffset+size(onion,1));
% extract region from peppers and compare to onion
extracted_onion = peppers(ybegin:yend,xbegin:xend,:);
if isequal(onion,extracted_onion) 
   disp('onion.png was extracted from peppers.png')
end
recovered_onion = uint8(zeros(size(peppers)));
recovered_onion(ybegin:yend,xbegin:xend,:) = onion;
imshow(recovered_onion)


% --- Executes on button press in transparent.
function transparent_Callback(hObject, eventdata, handles)
% hObject    handle to transparent (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
subplot(3,3,8)
global onion;
global peppers;
% non-interactively
rect_onion = [111 33 65 58];
rect_peppers = [163 47 143 151];
sub_onion = imcrop(onion,rect_onion);
sub_peppers = imcrop(peppers,rect_peppers);
c = normxcorr2(sub_onion(:,:,1),sub_peppers(:,:,1));
 % offset found by correlation
[max_c, imax] = max(abs(c(:)));
[ypeak, xpeak] = ind2sub(size(c),imax(1));
corr_offset = [(xpeak-size(sub_onion,2)) 
               (ypeak-size(sub_onion,1))];
% relative offset of position of subimages
rect_offset = [(rect_peppers(1)-rect_onion(1)) 
               (rect_peppers(2)-rect_onion(2))];
  •  

三、运行结果

在这里插入图片描述

完整代码或者仿真咨询添加QQ1575304183

以上是关于图像配准基于互相关图像配准matlab源码含GUI的主要内容,如果未能解决你的问题,请参考以下文章

图像配准基于Horn-Schunck和Lucas-Kanade等光流场实现图像配准matlab源码含GUI界面

图像配准基于matlab GUI Powell+蚁群算法图像配准含Matlab源码 928期

图像配准基于matlab GUI Powell+蚁群算法图像配准含Matlab源码 031期

毕设题目:Matlab图像配准

图像配准基于matlab OpenSUFT图像配准含Matlab源码 1232期

图像融合基于matlab DSIFT多聚焦图像融合含Matlab源码 2224期