from
Circular Hough Trasform in Polar Domain
by Prakash Manandhar
Detects center (xc, yc) and radius R of circle in an image in the polar domain.
|
| HghCircle (f, theta_index_exclude)
|
function [r_c_d theta_c_d R_d] = HghCircle (f, theta_index_exclude)
% Circle Detection using Hough Transform
% Oct 14 2008 Prakash Manandhar, pmanandhar@umassd.edu
theta_index_MAX = size(f, 2);
r_index_MAX = size(f, 1);
del_theta = 2*pi/(theta_index_MAX-1);
theta_values = 0:del_theta:2*pi;
theta_c_index_MAX = 20;
del_theta_c = 2*pi/(theta_c_index_MAX - 2);
theta_c_values = 0:del_theta_c:(2*pi - del_theta_c);
r_c_MIN = 0;
r_c_MAX = r_index_MAX/2;
del_r_c = r_index_MAX/20;
r_c_values = r_c_MIN:del_r_c:r_c_MAX;
R_min = 0.1*r_index_MAX;
R_max = 0.7*r_index_MAX;
del_R = 0.1*r_index_MAX;
R_bin_mins = R_min:del_R:R_max;
R_bin_maxs = (R_min + del_R):del_R:(R_max + del_R);
bins = zeros(length(r_c_values), length(theta_c_values), length(R_bin_mins));
for theta_index = 1:theta_index_MAX
if theta_index == theta_index_exclude
continue
end
theta = theta_values(theta_index);
for r = 1:r_index_MAX
for r_c_index = 1:length(r_c_values)
r_c = r_c_values(r_c_index);
for theta_c_index = 1:length(theta_c_values)
theta_c = theta_c_values(theta_c_index);
R = sqrt(r*r + r_c*r_c - 2*r*r_c*cos(theta - theta_c));
if R < (r_c + 10) | (R + r_c) > r_index_MAX
continue
end
for R_bin_index = 1:length(R_bin_mins)
if R >= R_bin_mins(R_bin_index) && R <= R_bin_maxs(R_bin_index)
bins(r_c_index, theta_c_index, R_bin_index) = ...
bins(r_c_index, theta_c_index, R_bin_index) + f(r, theta_index);
break;
end
end % R_bin_index
end % theta_c_index
end % r_c index
end % r
end % theta_index
r_c_d = 0;
theta_c_d = 0;
R_d = 0;
max_f = -1;
for r_c_index = 1:length(r_c_values)
for theta_c_index = 1:length(theta_c_values)
for R_bin_index = 1:length(R_bin_mins)
val = bins(r_c_index, theta_c_index, R_bin_index);
if (val > max_f)
max_f = val;
r_c_d = r_c_values(r_c_index);
theta_c_d = theta_c_values(theta_c_index);
R_d = (R_bin_mins(R_bin_index) + R_bin_maxs(R_bin_index))/2;
end
end % R_bin_index
end % theta_c_index
end % r_c index
|
|
Contact us