边缘⽅向直⽅图
边缘直⽅图能较好体现图像的边缘和纹理特征。不同类型的模板边缘直⽅图特征有⽐较明显的差异。边缘直⽅图的算法[1]具体如下:
(1) 图像灰度化。
(2) 将图像进⾏边缘算⼦ (如 SOBEL)运算, 得到( x, y) 点的 dx 和 dy。
(3) 计算各个像素的边缘⽅向θ( x, y) = argtg( dx / dy) 。
(4) 将边缘⽅向值进⾏量化, 从 0°~180°量化到 0°~36°。
(5) 将边缘⽅向值θ进⾏直⽅图统计并归⼀化。
Matlab代码[2](采⽤canny边缘检测):
rgb_img=imread('man.jpg');
gray_img=rgb2gray(rgb_img);
subplot(2,1,1);imshow(gray_img);
[row,col]=size(gray_img);
gray_img=double(gray_img);
% 使⽤canny算⼦,提取边缘
edge_canny=edge(gray_img,'canny');
edge_num=sum(sum(edge_canny));%边缘总点数
subplot(2,1,2);imshow(edge_canny);
%计算梯度⽮量Gx,Gy
for cir1=2:row-1
for cir2=2:col-1
Gx(cir1,cir2)=sum(gray_img(cir1-1:cir1+1,cir2+1))-sum(gray_img(cir1-1:cir1+1,cir2-1))...
+gray_img(cir1,cir2+1)-gray_img(cir1,cir2-1);
Gy(cir1,cir2)=sum(gray_img(cir1+1,cir2-1:cir2+1))-sum(gray_img(cir1-1,cir2-1:cir2+1))...
+gray_img(cir1+1,cir2)-gray_img(cir1-1,cir2);
Gx(cir1,cir2)=Gx(cir1,cir2)+(Gx(cir1,cir2)==0)*1e-6; % 为避免分母为0,加上⼀个很⼩的值。
theta(cir1,cir2)=atan2(Gy(cir1,cir2),Gx(cir1,cir2))*180/pi;
%atan2:计算边缘⽅向;范围:[-pi,pi];弧度->⾓度: [-180,180]
end
end
% 将[-180,180]每10度分为⼀组,那么⽅向被量化为36 bin
TH=[-170,-160,-150,-140,-130,-120,-110,-100,-90,-80,  -70,  -60,  -50,  -40,  -30,  -20,  -10,  0,...
10,  20,    30,  40,  50,  60,  70,  80,  90,100, 110,  120,  130, 140, 150,  160, 170,180;...
-180,-170,-160,-150,-140,-130,-120,-110,-100,-90,-80,-70,-60,-50,-40,-30,-20,-10,0,...matlab直方图
10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160,170];
% 存储各⽅向像素数⽬的数组
bar_hist= zeros(1,36);
ge_theta=theta&edge_canny;
for cir1=1:row
for cir2=1:col
for k=1:36
if (edge_canny(cir1,cir2)==1 & theta(cir1,cir2)
=TH(2,k))
bar_hist(k)=bar_hist(k)+1;
end
end
end
end
disp(bar_hist);
x=1:36;
figure;
bar(x,bar_hist(x));
[3]另⼀代码见:www.zhizhihu/html/y2009/41.html
参考⽂献:
[1]基于边缘直⽅图的快速汽车标志识别⽅法
[2]hi.baidu/tqjcwtcdgzcjrse/item/4673d9d2d88a02c81a72b413

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。