3

ハフ変換を使用してバイナリ イメージ内の最強の線を検出する方法を知っている人はいますか。

A = zeros(7,7);
A([6 10 18 24 36 38 41]) = 1;

-45° から 90° まで 45° のステップでシータを含む (rho; theta) 形式を使用します。また、MATLAB でもアキュムレータ配列を表示するにはどうすればよいですか。

ヘルプやヒントはありますか?

ありがとうございました!

4

2 に答える 2

5

Image Processing Toolboxにアクセスできる場合は、関数HOUGHHOUGHPEAKS、およびHOUGHLINESを使用できます。

%# your binary image
BW = false(7,7);
BW([6 10 18 24 36 38 41]) = true;

%# hough transform, detect peaks, then get lines segments
[H T R] = hough(BW);
P  = houghpeaks(H, 4);
lines = houghlines(BW, T, R, P, 'MinLength',2);

%# show accumulator matrix and peaks
imshow(H./max(H(:)), [], 'XData',T, 'YData',R), hold on
plot(T(P(:,2)), R(P(:,1)), 'gs', 'LineWidth',2);
xlabel('\theta'), ylabel('\rho')
axis on, axis normal
colormap(hot), colorbar

%# overlay detected lines over image
figure, imshow(BW), hold on
for k = 1:length(lines)
    xy = [lines(k).point1; lines(k).point2];
    plot(xy(:,1), xy(:,2), 'g.-', 'LineWidth',2);
end
hold off

ハフ 行

于 2011-07-14T18:14:55.313 に答える
1

各ピクセル (x,y) は、それを通る一連の線 (rho,theta) にマップされます。

  1. (rho theta) でインデックス付けされたアキュムレータ行列を作成します。
  2. オンになっている各ポイント (x,y) について、(x,y) に対応するすべての量子化された (rho, theta) 値を生成し、アキュムレータ内の対応するポイントをインクリメントします。
  3. 最も強い線を見つけることは、アキュムレータでピークを見つけることに対応します。

実際には、極パラメータの記述は正しく行うことが重要です。細かすぎると十分なポイントが重なりません。粗すぎると、各ビンが複数の行に対応する可能性があります。

自由のある疑似コードで:

accum = zeros(360,100);
[y,x] = find(binaryImage);
y = y - size(binaryImage,1)/2;  % use locations offset from the center of the image
x = x - size(binaryImage,2)/2;
npts = length(x);
for i = 1:npts
    for theta = 1:360  % all possible orientations
        rho = %% use trigonometry to find minimum distance between origin and theta oriented line passing through x,y here
        q_rho = %% quantize rho so that it fits neatly into the accumulator %% 
        accum(theta,rho) = accum(theta,rho) + 1;
    end
end
于 2011-07-13T15:18:19.360 に答える