欢迎光临散文网 会员登陆 & 注册

【图像拼接】基于Harris角点检测实现图像拼接含Matlab源码

2022-09-10 11:00 作者:Matlab工程师  | 我要投稿

1 简介

Harris 角点检测算法是由 C.Harris 和 J.Stephens 在 1988 年提出,此算法的原理是建立在 Moravec 算法的基础上进行大幅改进的,相比之前的算法更具明显的优势。Moravec如上文中的介绍说明,相比 Harris 检测算法而言,

Moravec 检测算法仅仅只是是在水平、垂直、对角线和反对角线四个方向上对灰度变化的信息进行处理,而 Harris 检测算法受到数学理论泰勒(Taylor

)级数的启发,以此展开思路,已不只是限定于四个方向,而是计算窗口内沿任意方向的灰度变化情况,最终利用数学解析式进一步确定所需特征点。并且算法引入高斯平滑算子,更加优化了算法自身的鲁棒性。不仅如此,Harris 

检测算法还受到信号处理中自相关函数的启迪,从而使用了自相关函数相关联的 M 矩阵。

该算法中 M 矩阵的特征值即自相关函数的一阶求导函数,判断该点是否为特征点即看此处像素点的曲率值是否够高。

2 部分代码

function [imgout]=warpTheImage(H,img1,img2)tform = maketform('projective',H');img21 = imtransform(img2,tform); % reproject img2% [M1 N1 dim] = size(img1);[M2 N2 dimk1] = size(img2);% do the mosaicpt = zeros(3,4);pt(:,1) = H*[1;1;1];pt(:,2) = H*[N2;1;1];pt(:,3) = H*[N2;M2;1];pt(:,4) = H*[1;M2;1];x2 = pt(1,:)./pt(3,:);y2 = pt(2,:)./pt(3,:);up = round(min(y2));Yoffset = 0;if up <= 0  Yoffset = -up+1;  up = 1;endleft = round(min(x2));Xoffset = 0;if left<=0  Xoffset = -left+1;  left = 1;end[M3 N3 dimk2] = size(img21);rowBegin=max(up,Yoffset+1); %overlap AreacolumnBegin=max(left,Xoffset+1);rowEnd=min(up+M3-1,Yoffset+M1);columnEnd=min(left+N3-1,Xoffset+N1);imgout(up:up+M3-1,left:left+N3-1,:) = img21;overlapAreaP2=imgout(rowBegin:rowEnd,columnBegin:columnEnd,:);%pixel values of overlap area from P2% img1 is above img21imgout(Yoffset+1:Yoffset+M1,Xoffset+1:Xoffset+N1,:) = img1;overlapAreaP1=imgout(rowBegin:rowEnd,columnBegin:columnEnd,:); overlapArea=imgout(rowBegin:rowEnd,columnBegin:columnEnd); [overRowLength,overColumnLength]=size(overlapArea);%overlap Row and Column length distFromBound1OneLine=(overColumnLength-1:-1:0);%this is just one line distFromBound1=repmat(distFromBound1OneLine,overRowLength,1);  %Replicate and tile it to the size of the overlapArea. Because the same column has the same distance to the boundary distFromBound2OneLine=(0:overColumnLength-1); distFromBound2=repmat(distFromBound2OneLine,overRowLength,1);%this the dist from boundary 2 % blending%  blendingImg(:,:,:)=(overlapAreaP2(:,:,:).*distFromBound2+overlapAreaP1(:,:,:).*distFromBound1)/(overColumnLength-1);% imshow(blending)overlapAreaP2=double(overlapAreaP2);overlapAreaP1=double(overlapAreaP1);blendingImg=zeros(overRowLength,overColumnLength,3);for i=1:3blendingImg(:,:,i)=(overlapAreaP2(:,:,i).*distFromBound2+overlapAreaP1(:,:,i).*distFromBound1)/(overColumnLength-1);endblendingImg=uint8(blendingImg);% imshow(blendingImg);title('after blending'); imgout(rowBegin:rowEnd,columnBegin:columnEnd,:)=blendingImg;end

3 仿真结果

4 参考文献

[1]贾莹. 基于Harris角点检测算法的图像拼接技术研究[D]. 吉林大学.

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。



【图像拼接】基于Harris角点检测实现图像拼接含Matlab源码的评论 (共 条)

分享到微博请遵守国家法律