我是计算机视觉的新手,我正在为霍夫变换编写自己的代码,我发现了以下算法:
算法:
• The cell (i,j) corresponds to the square associated
with parameter values (θj, ρi).
• Initialize all cells with value 0.
• For each foreground point (xk,yk) in the thresholded
edge image
– Let θj equal all the possible θ-values
• Solve for ρ using ρ=x cos θj +ysin θj
• Round ρ to the closest cell value, ρq
• Increment A(i,q) if the θj results in ρq
• After this procedure, A(i,j)=P means that P points in
the xy-space lie on the line ρj=x cos θj +ysin θj
• Find line candiates where A(i,j) is above a suitable
threshold
我已经编写了代码来增加霍夫累加器数组的索引。
我的代码:
%%
% Hough Transform
[rows,cols] = size(E); % size of edged image
rhomax = ceil (sqrt(rows^2 + cols^2)); % maximum value of rho
rhomax = rhomax * 2; % multuplied with 2 to cater both +rho and -rho values
accu = zeros(rhomax, 101); % initialization of accumulaor array with rhomax and 101 possible theta values
for i =1:1:rows % for all rows
for j =1:1:cols % for all columns
if(E(i,j) ~= 0) % if the pixel is ONE (part of the edge) then process it
for theta = 85.0:0.1:95.0 % for the theta values 85.0 - 95.0
% computing the theta index for hough accumulator
theta_index = 0;
for k =85.0:0.1:theta
theta_index = theta_index + 1;
end
%---
rho = round (i*cos(theta) + j*sin(theta)); % computing the value of rho
% computing the rho index for hough accumulator
rho_index = 1;
if(rho < 0)
rho_index = rho_index + abs(rho);
elseif(rho > 0)
rho_index = rho_index + (rhomax/2) + rho;
elseif(rho == 0)
rho_index = rho_index + (rhomax/2);
end
%---
accu(rho_index,theta_index) = accu(rho_index,theta_index)+1; % incrementing the corresponding index in accumulator
end
end
end
end
现在我想进一步处理阈值。如果有人告诉我应该如何选择我的阈值,我将不胜感激?