基于matlab的hough变换检测圆,并可以对两个重叠的圆进行检测

305 阅读1分钟

1.算法描述

        对于直角坐标系里的一条直线l,可用ρ,θ来表示该直线,相应的直线方程为ρ = x c o s θ + y s i n θ ρ=xcosθ+ysinθρ=xcosθ+ysinθ,其中,ρ是原点到该直线的垂直距离,θ是垂线与x轴的夹角,这条直线是惟一的。构造一个参数(ρ,θ)的平面,从而(ρ,θ)平面的一点,对应一条直线。根据点-线对偶性把检测问题转换到参数空间,通过简单的累加统计完成检测任务。

1.在参数空间(ρ,θ)里建立一个2D累加数组A(ρ,θ),初始化为0;

2.对XY空间中的每一个给定点做Hough变换,让θ在[θmin,θmax]区间取所有可能的值,并求出ρ;

3.根据ρ,θ取整数值在A(ρ,θ)处累加A(ρ,θ)=A(ρ,θ)+1,A(ρ,θ)的值说明多少点是共线的,最大值所对应的(ρ,θ)的值也对应了直线方程的参数。

 

2.仿真效果预览

matlab2022a仿真结果如下:

1.png

2.png

3.png

3.MATLAB核心程序

`rawimg = imread('test1.bmp');

tic;

[accum, circen, cirrad] = CircularHough_Grd(rawimg, [15 60]);

toc;

%figure(1); imagesc(accum); axis image;

%title('Accumulation Array from Circular Hough Transform');

figure(2); imagesc(rawimg); colormap('gray'); axis image;

hold on;

plot(circen(:,1), circen(:,2), 'r+');

for k = 1 : size(circen, 1),

    DrawCircle(circen(k,1), circen(k,2), cirrad(k), 32, 'b-');

end

hold off;

title(['Raw Image with Circles Detected ', ...

'(center positions and radii marked)']);

figure(3); surf(accum, 'EdgeColor', 'none'); axis ij;

title('3-D View of the Accumulation Array');

A_072`