How to find line using Hough Transform
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
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.
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
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.
could you please help me to connect dashed lines in the top and bottom to the end of the image ? @Image Analyst
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().
could you please tell me how to save the figure that hough transform apply on it to be saved image ? Image Analyst
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
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!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)

