ハフ変換から得た直線の始点と終点を関数としてプログラム内で使用するにはどうすればいいですか。
Show older comments
ハフ変換で得た直線を延長して二本の直線を交差させたいです。また、得た直線の始点からx軸に平行な線を引きたいです。 ハフ変換から得た直線の始点と終点を関数としてプログラム内で使用するにはどうすればいいですか。 書いたプログラムと使用した画像は添付しました。
I = imread('miti8.png');
RSI=imresize(I,0.5);
ID = imadjust(RSI,[0.7 0.7 0; 0.8 0.8 1],[]);
RS= imcrop(ID,[0.5 65.5 378 439]);
GSI=rgb2gray(RS);
figure
imshow(GSI)
J = imnoise(GSI,'salt & pepper',0.1);
K = medfilt2(J);
figure
imshow(K)
IB = imbinarize(K,0.2)
%小さいオブジェクトを削除
BR = bwareaopen(IB,150);
figure
imshow(BR);
%エッジ
BW = edge(BR,'Roberts');
figure
imshow(BW);
stats=regionprops('table',BR,'Centroid',...
'Extrema','Perimeter')
%ハフ変換を作成
[H,theta,rho] = hough(BW,'RhoResolution',0.1,'ThetaResolution',0.03);
figure
imshow(imadjust(mat2gray(H)),[],...
'XData',theta,...
'YData',rho,...
'InitialMagnification','fit');
xlabel('\theta (degrees)')
ylabel('\rho')
axis on
axis normal
hold on
colormap(hot)
%ハフ変換のピーク値を検出
P = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
x = theta(P(:,2));
y = rho(P(:,1));
plot(x,y,'s','color','black');
%ラインを検出してプロット
lines = houghlines(BW,theta,rho,P,'FillGap',30,'MinLength',50);
figure, imshow(BW), hold on
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',1,'Color','green');
len(k) = norm(lines(k).point1 - lines(k).point2);
end
1 Comment
michio
on 12 Sep 2017
プログラム部分をコード表示に修正いたしました。
- ハフ変換で得た直線を延長して二本の直線を交差させたいです。
こちらは上記URLで解決済みでしょうか。
- 得た直線の始点からx軸に平行な線を引きたいです。
こちらも上記URLで紹介されたinsertShape関数などで表示できそうですが、いかがでしたでしょか。
- ハフ変換から得た直線の始点と終点を関数としてプログラム内で使用するにはどうすればいいですか。
この点、すいません。もう少し詳細に説明ください。直線の始点と終点を入力引数して受け付ける関数を定義されたい、ということでしょうか。
Answers (0)
Categories
Find more on イメージ カテゴリの分類と画像検索 in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!