필터 지우기
필터 지우기

Drawing a white line on an image using (rho, theta).

조회 수: 3 (최근 30일)
Ba Ba Black Sheep!
Ba Ba Black Sheep! 2017년 6월 19일
댓글: Ba Ba Black Sheep! 2017년 6월 20일
I want to draw a line on the following image using (| |rho , theta ) of the detected line using the Hough transformation.
.
expected output
.
What is wrong in the following code?
It's not being able to display the line.
input_image = gray_imread('Scratch1.1.png');
maxPeaks = 1;
fillgap = 500;
minline = 7;
binary_image = edge(input_image,'canny');
[H,T,R] = hough(binary_image);
threshPeaks = ceil(0.3*max(H(:)));
P = houghpeaks(H, maxPeaks, 'threshold', threshPeaks);
hlines = houghlines(binary_image, T, R, P, 'FillGap', fillgap, 'MinLength', minline);
h_line = hlines(1);
rho = h_line.rho;
theta = h_line.theta;
imshow(input_image);
hold on;
x = h_line.point1(1):h_line.point2(1);
y = (rho - x* cos(theta) )/ sin(theta);
plot(x,y);
  댓글 수: 2
Julian Hapke
Julian Hapke 2017년 6월 19일
편집: Julian Hapke 2017년 6월 19일
There seems to be a Problem when you calculate x and y. The line is there but in the wrong location (try expanding the axis limits to see what I mean.) Also: Calculation of x and y (especially with interval 1 on x, it's just a line) is not necessary. If I use
hline = plot([h_line.point1(1) h_line.point2(1)],[h_line.point1(2) h_line.point2(2)],'w')
I get the results you seem to be expecting.
Ba Ba Black Sheep!
Ba Ba Black Sheep! 2017년 6월 20일
This is incorrect answer. Using sind and cosd solved my problem.

댓글을 달려면 로그인하십시오.

답변 (1개)

Julian Hapke
Julian Hapke 2017년 6월 20일
My comment was the answer, so to stick to the structure of this forum:
Your calculation of x and y yields to wrong values. If you use the end points of the houghlines directly
hline = plot([h_line.point1(1) h_line.point2(1)],[h_line.point1(2) h_line.point2(2)],'w')
you get the line you showed in your "expected output"
Please mark this as answer if it fits your needs.

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by