transformada de hough

2
Ejemplo Transformada Hough Matlab clc clear all close all imagen=imread('linea.bmp'); subplot(2,2,1) imshow(imagen) title('Imagen Original') %Binarización imagen level=graythresh(imagen); bn=im2bw(imagen,level); subplot(2,2,2) imshow(bn) title('Imagen Binarizada') %preprocesamiento bn=edge(bn,'sobel','vertical'); subplot(2,2,3) imshow(bn) title('Imagen filtrada: detec. de bordes') subplot(2,2,4) imshow(imagen); [H,T,R]=hough(bn); peaks=houghpeaks(H,5); lines=houghlines(bn,T,R,peaks); hold on max_len=0; for k=1:length(lines) xy=[lines(k).point1; lines(k).point2];  plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green'); % dibuja el principo y el final de cada segmento  plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow'); plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red'); % dibuja el segmento len=norm(lines(k).point1 - lines(k).point2);  

Upload: carlos-carranza

Post on 13-Oct-2015

5 views

Category:

Documents


0 download

TRANSCRIPT

Ejemplo Transformada Hough Matlab

clcclearallcloseall

imagen=imread('linea.bmp');subplot(2,2,1)imshow(imagen)

title('Imagen Original')

%Binarizacin imagenlevel=graythresh(imagen);bn=im2bw(imagen,level);subplot(2,2,2)imshow(bn)

title('Imagen Binarizada')

%preprocesamientobn=edge(bn,'sobel','vertical');subplot(2,2,3)imshow(bn)

title('Imagen filtrada: detec. de bordes')

subplot(2,2,4)imshow(imagen);

[H,T,R]=hough(bn);peaks=houghpeaks(H,5);lines=houghlines(bn,T,R,peaks);

holdon

max_len=0;

fork=1:length(lines)xy=[lines(k).point1; lines(k).point2];plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');% dibuja el principo y el final de cada segmentoplot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');

% dibuja el segmentolen=norm(lines(k).point1 - lines(k).point2);if( len > max_len) max_len = len; xy_long = xy;endend

title('Imagen original y 5 primeras lneas')