matlab 霍夫变换 检测车辆,matlab 霍夫变换—检测圆

文件1---hough_circle.m

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:阈值,0,1之间的数 通过调此值可以得到图中圆的圆心和半径

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% output

% hough_space:参数空间,h(a,b,r)表示圆心在(a,b)半径为r的圆上的点数

% hough_circl:二值图像,检测到的圆

% para:检测到的圆的圆心、半径

circleParaXYR=[];

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&a<=m&b>0&b

你可能感兴趣的:(matlab,霍夫变换,检测车辆)