%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% a: model RGB image %
% b: target RGB image %
% c: output the match image %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [ c ] = edge_match( a,b)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%用sobel掩膜提取边缘并保留边缘点的梯度方向与ang数组中%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ma=im2double(rgb2gray(a)); %样本图像
mb=im2double(rgb2gray(b)); %模板
%水平与竖直方向的sobel掩膜
mask_Ver= fspecial('sobel'); %垂直方向上的掩膜
mask_Lev= mask_Ver'; %水平方向掩膜
%图像在水平方向和垂直方向上对sobel算子的响应
imgSobel_Lev=imfilter(ma,double(mask_Lev),'corr','replicate','same');
imgSobel_Ver=imfilter(ma,double(mask_Ver),'corr','replicate','same');
%imwrite(imgSobel_Ver,'Ver.jpg');
%imwrite(imgSobel_Lev,'Lev.jpg');
%%
%计算模板特征点角度
[Row,Col]=size(ma);
for i=1:Row
for j=1:Col
imgEdge(i,j)=sqrt(imgSobel_Ver(i,j)*imgSobel_Ver(i,j)+imgSobel_Lev(i,j)*imgSobel_Lev(i,j));
if(imgSobel_Lev(i,j)==0)
temp=0;
elseif(imgSobel_Ver(i,j)==0)
temp=90.0;
else
temp =atan(imgSobel_Lev(i,j)/imgSobel_Ver(i,j));
end
if(temp<0)
temp=180*(pi+temp)/(pi);
else
temp=180*temp/(pi);
end
%将角度归为0,45,90,135,四个方向
if((temp<22.5)||(temp>157.5))
ang(i,j)=0;
elseif(temp>=22.5&&temp<=67.5)
ang(i,j)=45;
elseif(temp&g
基于边缘的模板匹配
最新推荐文章于 2023-07-22 10:06:02 发布
本文介绍了基于边缘计算的模板匹配方法,通过将计算任务下放到设备边缘,提高匹配效率和响应速度。针对目标检测,该技术实现了快速准确的识别结果。
摘要由CSDN通过智能技术生成