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
| % Chargement d'une image RGB
rgb = imread('ngc6543a.jpg');
% Ouverture d'un objet Figure
figure
% Affichage de l'image originale
subplot(2,1,1)
image(rgb)
% Réglage de l'affichage au dimension de l'image
axis image
% Génération d'un triangle aléatoire
[r,c]=size(rgb(:,:,1));
x=round(rand(1,3)*r);
y=round(rand(1,3)*c);
% Paramètrage de l'objet Axes pour pouvoir superposer le triangle sur
% l'image
hold on
% Tracé du triangle en vert sur l'image RGB
plot([x x(1)],[y y(1)],'g-');
% Génération de tous les couples des indices des pixels
[xpix,ypix]=meshgrid(1:c,1:r);
% Recherche des indices des pixels contenus dans le triangle
in=inpolygon(xpix,ypix,x(:),y(:));
% Modification des pixels correspondant <= PARTIE A ADAPTER
in=uint8(in);
rgb(:,:,1)=rgb(:,:,1).*uint8(in);
rgb(:,:,2)=rgb(:,:,2).*uint8(in);
rgb(:,:,3)=rgb(:,:,3).*uint8(in);
% Affichage des pixels modifiés
subplot(2,1,2)
image(rgb)
axis image |