图像处理——霍夫变换

hough变换用于检测直线,matlab中有hough的实现,不过是用C语言实现的,看不到源码。(matlab-hough
下面是我自己的实现。

function hough_space = hough_transform(img_binary);
% get the hough transformation 
% img_binary: binary image
% hough_space: response in hough space
% x * cos(theta) + y * sin(theta) = r

theta_max = pi;
theta_count = 180;
theta_step = theta_max/theta_count;

img_size = size(img_binary);
center = img_size./2;
r_max = norm(img_size)*2;
r_count = r_max;
r_step = r_max/r_count;

hough_space = zeros(r_count,theta_count);
for i=1:img_size(1)
    for j=1:img_size(2)
        if ~img_binary(i,j)
            continue;
        end
        for k=1:theta_count
            theta = k*theta_step;
            r = int16((j-center(2))*cos(theta)-((i-center(1))*sin(theta)));
            r = r/r_step;
            r = r+r_max/2;
            if r>0 && r<r_max
                hough_space(r, k) = hough_space(r, k)+1;
            end
        end
    end
end
figure;
imshow(hough_space/max(hough_space(:)));

end

算法参考matlab的实现:matlab-hough algorithm
坐标定义如下:(图片来自matlab doc)
这里写图片描述


测试如下:
对点的检测
这里写图片描述
这里写图片描述
对线的检测
这里写图片描述
这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值