如何设置霍夫变换的阈值

信息处理 图像处理 霍夫变换
2022-02-16 20:09:54

我是计算机视觉的新手,我正在为霍夫变换编写自己的代码,我发现了以下算法:

算法:

• 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

现在我想进一步处理阈值。如果有人告诉我应该如何选择我的阈值,我将不胜感激?

1个回答

好吧,这实际上取决于您希望在图像中找到什么。 matlab 函数使用最大峰值一半的示例阈值。

你在什么样的图像上使用它?


因此,基于仅在图像中找到垂直线,让我们做出一些假设。

  • 你的矩形的最小垂直边长是Lmin像素。
  • 您的边缘检测只能找到每个边缘的 80%。

那么最小阈值为

0.8Lmin

例如,如果您的边缘往往比 80% 的数字更厚或更薄,您就需要对此进行修改。