0
画像に線を見つけて、見つかった線の上に赤い線を引くコードを記述しようとしています。私はハフ変換を使用してこれを行うことができましたが、私の問題は水平線と垂直線だけを見つけて、他のすべての斜面の線を残すことです。Matlabで水平線と垂直線のみを見つけるようにハフ変換をフィルタリングする
私は、コードが見つけた行の傾きを見つけて、if文を使って水平線と垂直線の上に赤い線だけを表示することでこれを解決できると考えていますが、 xとyの値を見つけることができます。
この問題を解決する方法はありますか?ここで
は、以下の私のコードです:
function findlineshv(I)
% Read Image
img = imread(I);
% Convert to black and white because
% edge function only works with BW imgs
bwImage = rgb2gray(img);
% figure(1),imshow(bwImage);
% find edges using edge function
b=edge(bwImage,'sobel');
% show edges
% figure(1),imshow(b);
% compute the Hough transform of the edges found
% by the edge function
[hou,theta,rho] = hough(b);
% define peaks, x and y
peaks = houghpeaks(hou,5,'threshold',ceil(0.3*max(hou(:))));
x = theta(peaks(:,2));
y = rho(peaks(:,1));
lines = houghlines(bwImage,theta,rho,peaks,'FillGap',5,'MinLength',7);
figure, imshow(bwImage), hold on
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',3,'Color','red');
end
ちょっとしたヒント:イメージを共有すると、より迅速な対応が得られるかもしれません。 – tfv