How to find line using Hough Transform
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Hi I have a matrix of coordinates such
BW = [380 .2134;
380.95 .1784;
381.05 .1374]
and I would like to identify lines using Hough transform. Unfortunately, I do not know how. Examples do not work for my data.
採用された回答
Image Analyst
2013 年 12 月 14 日
Either convert your list of coordinates to a binary image
for k = 1 : size(BW, 1);
binaryImage(BW(k, 2), BW(k, 1)) = true;
end
or else use RANSAC: https://en.wikipedia.org/wiki/Ransac to identify lines in a collection of arbitrary points.
11 件のコメント
Bartosz
2013 年 12 月 14 日
Thanks a lot ! I will check this other method But how to do binaryImage when I have data in BW like 0.2184 I need scalar to do this.
Image Analyst
2013 年 12 月 14 日
You need to convert those numbers to an integer that is the row and column. So pick a resolution, say the resolution of your original image or make up something like 1024x1280 or whatever. Then get the row and column like
row = int32(y * 1280;
col = int32(x * 1024);
Dina Abdeltwab
2020 年 1 月 7 日
編集済み: Dina Abdeltwab
2020 年 1 月 7 日
i want to apply line hough transform to the image in the previous comment to give me two straight lines as shown in the next comment and then superimposing the lines on the original gray scale image , could you help me ,please? Image Analyst
Dina Abdeltwab
2020 年 1 月 7 日

Image Analyst
2020 年 1 月 7 日
Just call polyfit
% Find the top and bottom lines.
x = 1 : columns;
topCurve = zeros(1, columns);
bottomCurve = zeros(1, columns);
for col = 1 : columns
topCurve(col) = find(binaryImage(:, col), 1, 'first');
bottomCurve(col) = find(binaryImage(:, col), 1, 'last');
end
% Fit top curve to line
topCoefficients = polyfit(x, topCurve, 1);
yFitTop = polyval(topCoefficients, x);
hold on
plot(x, yFitTop, 'r-', 'LineWidth', 3);
% Fit bottom curve to line
bottomCoefficients = polyfit(x, bottomCurve, 1);
yFitBottom = polyval(bottomCoefficients, x);
hold on
plot(x, yFitBottom, 'r-', 'LineWidth', 3);

See attached m-file for a full demo.
Dina Abdeltwab
2020 年 1 月 8 日
could you please help me to connect dashed lines in the top and bottom to the end of the image ? @Image Analyst
Image Analyst
2020 年 1 月 8 日
Since you have the endpoints, you can just use polyfit() to get the equation of the line connecting the two endpoints, then use polyval() to get the y values between the two end points. See my code for examples of how to use polyfit() and polyval().
Dina Abdeltwab
2020 年 1 月 8 日
could you please tell me how to save the figure that hough transform apply on it to be saved image ? Image Analyst
Image Analyst
2020 年 1 月 8 日
Did you try what I said, about using polyfit() and polyval()? If not, why not? Did you put your two endpoints into polyfit
coefficients = polyfit([x1, x2], [y1, y2], 1);
and then get the line y values between x1 and x2?
xLine = x1:x2;
yLine = polyval(coefficients, xLine);
So now you have the x and y locations between endpoint (x1, y1) and (x2, y2). Just 3 lines of code so I'm sure you tried it, so what happened?
Or, on re-reading your question I guess you did use them and your actual question is "how to save the figure", so for that I'd use imwrite() to save the image alone, and export_fig() if you want to save the whole window (with axes labels, tick marks, etc.)
Dina Abdeltwab
2020 年 1 月 9 日
編集済み: Dina Abdeltwab
2020 年 1 月 9 日
Thanks alot for your help, i did it but by this it is manual not automatic and i want it to be automatic . last thing , the code of polyfit you mentioned to give two red lines on the binary image , could you tell me how to apply these two lines on the original gray scale image after applying them on it's binary image ? @Image Analyst .sorry for annoying you
Image Analyst
2020 年 1 月 9 日
You can burn the lines into the image like this:
for k = 1 : length(xLine)
col = round(xLine(k))
row = round(yLine(k))
grayImage(row, col) = 255;
end
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Get Started with Computer Vision Toolbox についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
