Monday, August 2, 2010

Hough Edge detection

clear all; close all; clc;
f = imread('House24.png');
f = rgb2gray(f);
f = imcrop(f,[3 3 255 255]);
%f = im2double(f);
%f = imrotate(f,33,'crop');
BW = edge(f,'canny');
[H, theta, rho] = hough(BW);
imshow(theta, rho, H, [], 'notruesize');
axis on, axis normal
xlabel('\theta'), ylabel('\rho');
p = houghpeaks(H,5,'threshold',ceil(0.3*max(H(:))));
c = theta(p(:,2));
r = rho(p(:,1));
hold on
plot(c,r, 'linestyle', 'none', 'marker', 'S', 'color', 'w');
lines = houghlines(BW,theta,rho,p,'FillGap',5,'MinLength',7);
figure,imshow(f), hold on
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
end

No comments: