Hough变换检测圆function [hough_space,hough_circle,para] = hough_circle(BW,step_r,step_angle,r_min,r_max,p) %% input% BW:二值图像;% step_r:检测的圆半径步长% step_angle:角度步长,单位为弧度% r_min:最小圆半径% r_max:最
来源:学生作业帮助网 编辑:作业帮 时间:2024/12/01 14:19:43
Hough变换检测圆function [hough_space,hough_circle,para] = hough_circle(BW,step_r,step_angle,r_min,r_max,p) %% input% BW:二值图像;% step_r:检测的圆半径步长% step_angle:角度步长,单位为弧度% r_min:最小圆半径% r_max:最
Hough变换检测圆
function [hough_space,hough_circle,para] = hough_circle(BW,step_r,step_angle,r_min,r_max,p)
%
% input
% BW:二值图像;
% step_r:检测的圆半径步长
% step_angle:角度步长,单位为弧度
% r_min:最小圆半径
% r_max:最大圆半径
%p:以p*hough_space的最大值为阈值,p取0,1之间的数
%
% output
% hough_space:参数空间,h(a,b,r)表示圆心在(a,b)半径为r的圆上的点数
% hough_circl:二值图像,检测到的圆
% para:检测到的圆的圆心、半径
[m,n] = size(BW);
size_r = round((r_max-r_min)/step_r)+1;
size_angle = round(2*pi/step_angle);
hough_space = zeros(m,n,size_r);
[rows,cols] = find(BW)
ecount = size(rows);
% Hough变换
% 将图像空间(x,y)对应到参数空间(a,b,r)
% a = x-r*cos(angle)
% b = y-r*sin(angle)
for i=1:ecount
for r=1:size_r
for k=1:size_angle
a = round(rows(i)-(r_min+(r-1)*step_r)*cos(k*step_angle));
b = round(cols(i)-(r_min+(r-1)*step_r)*sin(k*step_angle));
if(a>0&a0&b=max_para*p);
length = size(index);
hough_circle = false(m,n);
for i=1:ecount
for k=1:length
par3 = floor(index(k)/(m*n))+1;
par2 = floor((index(k)-(par3-1)*(m*n))/m)+1;
par1 = index(k)-(par3-1)*(m*n)-(par2-1)*m;
if((rows(i)-par1)^2+(cols(i)-par2)^2(r_min+(par3-1)*step_r)^2-5)
hough_circle(rows(i),cols(i)) = true;
end
end
end
% 打印检测结果
for k=1:length
par3 = floor(index(k)/(m*n))+1;%向负方向舍入取整
par2 = floor((index(k)-(par3-1)*(m*n))/m)+1;
par1 = index(k)-(par3-1)*(m*n)-(par2-1)*m;
par3 = r_min+(par3-1)*step_r;
fprintf(1,'Center %d %d radius %d\n',par1,par2,par3);
para(:,k) = [par1,par2,par3];
end
这段程序中
% 搜索超过阈值的聚集点
max_para = max(max(max(hough_space)));
index = find(hough_space>=max_para*p);
length = size(index);
hough_circle = false(m,n);
for i=1:ecount
for k=1:length
par3 = floor(index(k)/(m*n))+1;
par2 = floor((index(k)-(par3-1)*(m*n))/m)+1; %par3是半径,par1和par2是要检测的圆的坐标.
par1 = index(k)-(par3-1)*(m*n)-(par2-1)*m; %index(k)在hough_space中的三维位置(par1,par2,par3)
if((rows(i)-par1)^2+(cols(i)-par2)^2(r_min+(par3-1)*step_r)^2-5)
hough_circle(rows(i),cols(i)) = true; %判断点(rows(i),cols(i))是否在对应圆环内
end
end
end
这段是怎么找圆心的.在判断是否在圆环中 if((rows(i)-par1)^2+(cols(i)-par2)^2(r_min+(par3-1)*step_r)^2-5)
这句是啥意思为什么要+5和-5?
Hough变换检测圆function [hough_space,hough_circle,para] = hough_circle(BW,step_r,step_angle,r_min,r_max,p) %% input% BW:二值图像;% step_r:检测的圆半径步长% step_angle:角度步长,单位为弧度% r_min:最小圆半径% r_max:最
我的理解是这样的,在计算机编程中是不会那么确定某个数一定怎么怎么样的,例如,某两个数相减等于0,只会用一个精确度描述.我想,+5,-5应该这个意思.