【问题标题】:Implementing Edge Oriented Histogram实现面向边缘的直方图
【发布时间】:2014-08-15 03:08:35
【问题描述】:

我正在尝试实现面向边缘的直方图:但是代码中存在问题,我无法弄清楚val=fix((angles(i,j)-a_min)/(BinSize))+1; 要去哪里南

我要拿 8 个垃圾箱。 1.首先我使用sobel算子找到梯度和角度。 2. 后来我有 8 个 bin(-pi/2 到 pi/2,因为 atan 返回这两个值之间的值),我根据角度对梯度幅度进行 binning。

    im=imread('cameraman.tif');
subplot(2,2,1);imshow(im);
im=im2double(im);

sob_x=[-1,0,1;-2,0,2;-1,0,1];
sob_y=[1,2,1;0,0,0;-1,-2,-1];

im_x=imfilter(im,sob_x);
im_y=imfilter(im,sob_y);
subplot(2,2,2);imshow(im_x);
subplot(2,2,3);imshow(im_y);

im_edge=zeros(size(im));
angles=zeros(size(im));

[r c]=size(im);
for i=1:r
    for j=1:c
        im_edge(i,j)=sqrt(im_x(i,j)^2+im_y(i,j)^2);
        angles(i,j)=atan(im_y(i,j)/im_x(i,j));%angles are -pi/2 to pi/2
    end
end

subplot(2,2,4);imshow(im_edge,[]);

im_temp=im2bw(im_edge,80/255);
figure();subplot(1,2,1);imshow(im_temp);
subplot(1,2,2);imshow(angles,[]);

%calculating the histogram



No_bins=8;
H=zeros(1,No_bins);
BinSize=pi/No_bins;


a_min=-pi/2;
for i=1:r
    for j=1:c
        val=fix((angles(i,j)-a_min)/(BinSize))+1;
        if (val>8)
            val=8;
        end
        if(val<1)
            val=1;
        end

        H(1,val)=H(1,val)+im_edge(i,j);


end
end

H

【问题讨论】:

    标签: matlab image-processing histogram edge-detection sobel


    【解决方案1】:

    这个的实现 angles(i,j)=atan(im_y(i,j)/im_x(i,j));%angles are -pi/2 to pi/2 在一些像素中返回 Nan 值。您应该尝试在边缘像素处提取边缘方向。

    【讨论】:

      猜你喜欢
      • 2012-07-15
      • 2015-11-24
      • 2011-05-14
      • 2018-09-14
      • 2016-05-23
      • 2019-10-23
      相关资源
      最近更新 更多