Plotting lines in an efficient way.
Mostrar comentarios más antiguos
Hi,
I'm detecting lines on an image by the Hough transform, when I use the function houghlines, it return me a struct that I called lines, containing the start and the end point of the lines detected, I'm plotting it by a foor loop:
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','red');
end
In this manner I obtain this result:

But plotting all the lines with the foor loop takes a lots of time.
In order to speed up, the process I have written the following code:
xy = [];
for k = 1:length(lines)
point1 = lines(k).point1;
point2 = lines(k).point2;
xy = [xy; lines(k).point1; lines(k).point2];
end
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','red');
But the result is:

How I have to modify the script in order to obtain, the same result of the first image?
Respuesta aceptada
Más respuestas (1)
KSSV
el 8 de Mzo. de 2017
xy = [];
for k = 1:length(lines)
point1 = [lines(k).point1 NaN]; % if throws error try point1 = [lines(k).point1 ; NaN];
point2 = [lines(k).point2 NaN]; % if throws error try point1 = [lines(k).point2 ; NaN];
xy = [xy; point1; point2];
end
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','red');
1 comentario
Simone Cordella
el 8 de Mzo. de 2017
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!