基于边缘的模板匹配

本文介绍了基于边缘计算的模板匹配方法,通过将计算任务下放到设备边缘,提高匹配效率和响应速度。针对目标检测,该技术实现了快速准确的识别结果。
摘要由CSDN通过智能技术生成
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                          %
%   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
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值