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
|
%definir un carré:
x = [0,2; 0,0; 2,0 ;2,2; 0,2];
y = x + 1;
z = x + 5;
[x(:,1), x(:,2)] = poly2cw(x(:,1),x(:,2));
[y(:,1), y(:,2)] = poly2cw(y(:,1),y(:,2));
[z(:,1), z(:,2)] = poly2cw(z(:,1),z(:,2));
%Unions:
[X,Y] = polybool('union',x(:,1),x(:,2),y(:,1),y(:,2));
[X2,Y2] = polybool('union',X,Y,z(:,1),z(:,2));
s = polyarea(X2,Y2);
h = figure;
plot(x(:,1),x(:,2),'b-'); hold on;
plot(y(:,1),y(:,2),'r-');
plot(z(:,1),z(:,2),'r-');
axis equal;
%patch:
patch(x(:,1),x(:,2),'k')
patch(y(:,1),y(:,2),'k')
patch(z(:,1),z(:,2),'k')
%Export (sans les axes):
saveas(h, 'toto.jpg', 'jpg');
close
%Reimport:
BW = imread('toto.jpg','jpg');
%Binarise:
ZZ = BW > 255/2;
STATS = regionprops(double(ZZ(:,:,1)),'Area'); |
Partager