2017-12-26 16 views
0

に等価変換:私は「houghtfにハフ」を変更することにより、OCTAVEで同じことを実現しようとしているときにハフは、下のMATLABで</em>を変換し、私は<em>ハフのコードを添付したオクターブ

%Hough Transform to find lines 

%Load an Image and Convert to Grayscale to apply canny Filter 
im = imread('lines.jpg'); 
im_gray = rgb2gray(im); 
im_edge = edge(im_gray, 'canny'); 

figure, imshow(im), title('Original Image'); 
figure, imshow(im_gray), title('Grayscale Image'); 
figure, imshow(im_edge), title('Canny Filter Edge'); 

%Apply Hough Transform to Find the Candidate Lines 
[accum theta rho] = hough(im_edge); 
figure, imagesc(accum, 'xData', theta, 'ydata', rho), title('Hough Accumulator'); 

peaks = houghpeaks(accum, 100, 'Threshold', ceil(0.6 * max(accum(:))),'NHoodSize', [5,5]); 
size(peaks); 

%Finding the line segments in the image 
line_segs = houghlines(edges, theta, rows, peaks, 'FillGap', 50,'MinLength', 100); 

%Plotting 
figure, imshow(im), title('Line Segments'); 
hold on; 
for k=1:length(line_segs) 
    endpoints = [line_segs(k).point1; line_segs(k).point2]; 
    plot(endpoints(:,1), endpoints(:,2), 'LineWidth', 2, 'Color','green'); 
end 
hold off; 

、次のように 'immaximasにhoughpeaks'と'hough_lineにhoughlines':

%Hough Transform to find lines 
pkg load image; 

%Load an Image and Convert to Grayscale to apply canny Filter 
im = imread('lines.jpg'); 
im_gray = rgb2gray(im); 
im_edge = edge(im_gray, 'canny'); 

figure, imshow(im), title('Original Image'); 
figure, imshow(im_gray), title('Grayscale Image'); 
figure, imshow(im_edge), title('Canny Filter Edge'); 

%Apply Hough Transform to Find the Candidate Lines 
[accum theta rho] = houghtf(im_edge); %In Octave and 'hough' in MATLAB 
figure, imagesc(accum, 'xData', theta, 'ydata', rho), title('Hough Accumulator'); 

peaks = immaximas(accum, 100, 'Threshold', ceil(0.6 * max(accum(:))),'NHoodSize', [5,5]); 
size(peaks); 

%Finding the line segments in the image 
line_segs = hough_line(edges, theta, rows, peaks, 'FillGap', 50, 'MinLength', 100); 

%Plotting 
figure, imshow(im), title('Line Segments'); 
hold on; 
for k=1:length(line_segs) 
endpoints = [line_segs(k).point1; line_segs(k).point2]; 
plot(endpoints(:,1), endpoints(:,2), 'LineWidth', 2, 'Color', 'green'); 
end 
hold off; 
それを実行しながら私は次のエラーを取得する:

error: element number 3 undefined in return list 
error: called from 
HoughTransformLines at line 14 column 18 

私は「ロー」は未定義であるというエラーを取得しています。 私はMATLABとOctaveについて全く新しいです。誰でもオハイオ州でハフ変換を実装するのを助けてくれますか?

答えて

0

rhoが未定義である理由は、Matlabのhough関数とOctaveのhoughtf関数が完全に等価でないためです。

ここ対応Mathworkのウェブページからハフによって返された出力引数の説明は次のとおり

The function returns rho, the distance from the origin to the line along a vector perpendicular to the line, and theta, the angle in degrees between the x-axis and this vector. The function also returns the Standard Hough Transform, H, which is a parameter space matrix whose rows and columns correspond to rho and theta values respectively.

Octaveのhoughtf、一方、唯一行列Hを返す:

The result H is an N by M matrix containing the Hough transform. Here, N is the number different values of r that has been attempted. This is computed as 2*diag_length - 1, where diag_length is the length of the diagonal of the input image. M is the number of different values of theta. These can be set through the third input argument arg. This must be a vector of real numbers, and is by default pi*(-90:90)/180.

あなたのスクリプトで、rhoと呼ぶ唯一の場所は、Houghアキュムレータを表示しようとするとき、15行目です。 私はあなたの代わりにアキュムレータをこのようにプロット勧め:

figure, imagesc(H),xlabel('xData'),ylabel('ydata'),title('Hough accumulator') 

が、これはあなたのために働くなら、私を知ってみましょう!

+0

これは、アキュムレータをプロットする方法を示しています。 しかし、私は15行目から「ロー」を削除する必要がありました: '[ACCUM角度θ= houghtf(im_edge);' しかし、まだこのエラー取得: 'エラー:immaximas:3番目の入力引数は、スカラーかでなければなりません空行列 エラー: から呼び出されるimmaximas行76列5 HoughTransformLines行18列7' – Ranit

関連する問題