1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
%% Lecture de l'image:
originale=imread('2rectangle.jpg');
%% les différentes types de contour
I=rgb2gray(originale);
Ca = edge(double(I),'canny');
%% Transformée de hough:
[H,Theta,rho] = hough(Ca,'RhoResolution',0.5,'ThetaResolution',0.5);
figure(1)
imshow(imadjust(mat2gray(H)),[],'XData',Theta,'YData',rho,...
'InitialMagnification','fit');
xlabel('\Theta (degrees)'), ylabel('\rho');
axis on , axis normal,hold on
colormap(copper)
%% chercher des pics dans l'espace de Hough:
numpeaks=20;
P = houghpeaks(H,numpeaks,'threshold',ceil(0.3*max(H(:))));
x = Theta(P(:,2));
y = rho(P(:,1));
plot(x,y,'s','color','cyan');
lines = houghlines(Ca,Theta,rho,P,'FillGap',20,'MinLength',40);
figure(2)
imshow(I),axis on , axis normal,hold on,grid on
max_len = 0;
for z=1:length(x)
theta1=x(1,z);
rho1= y(1,z);
for v=z:length(x)
if z==v
continue
end
Tx=3;
theta2 = x(1,v);
rho2= y(1,v);
deltaTheta=abs(theta1-theta2);%Pour le parallèlisme
if deltaTheta < Tx
alphak =(1/2)*(theta1+theta2);
sigmak =(1/2)*abs(rho1-rho2);
P1=[sigmak,alphak]
end
end
end |
Partager