%affichage d'une image a partir d'une matrice 100*100
a= randn(100);
figure(1);
imshow(a)
%lire et afficher une image sous forme matricielle afficher les graduations et
la barres des couleurs
figure(2); imshow(a1);
axis on
colorbar;
%ouvrir 2 images au choix et les afficher sur le meme graphique
figure(3);
subplot(121);
imshow(a)
subplot(122);
imshow(a1);
%mettre une image au choix à niveau de gris puis en noir et blanc
a1b= im2bw(a1); figure(4); imshow(a1b);
a1g=rgb2gray(a1); figure(5); imshow(a1g);
figure(6); subplot(221); imshow(a1);title('original'); subplot(222);
imshow(a1b); title('black and white'); subplot(223); imshow(a1g);
title('gris');
%afficher une image en niveau de gris et son histogramme
figure(1);
B=imread('a1.jpg');imshow(B);
figure(2);
a1g=rgb2gray(B);imshow(a1g);
figure(3);
subplot(121); imshow(a1g);subplot(122); imhist(a1g);
%additionner 2 images
figure(4);
c=imread('a2.jpg');
d=imread('a3.jpg');
f=imadd(e,a3);imshow(f);
%e=imresize(a2, [size(a3,1) size(a3,2)]);
%imfinfo('a2.jpg');
figure(5);
g=imsubtract(e,a3);imshow(g);
%calcul de la valeur du pixel central de l'image de sortie filtrée par h
Is(2,2)
Ie=[4,125,255;7,0,45;9,56,13];
h=[0,-1,0;-1,5,-1;0,-1,0];
Is=imfilter(Ie,h,'conv');
Is(2,2);
figure(2);
B=imread('a1.jpg');imshow(B);
a1g=rgb2gray(B);imshow(a1g);
a1gb=imnoise(a1g,'salt & pepper');%appliquer un bruit de type poivre et sel
h1=ones(3,3)/9;%filtre moyenneur ou h1=[111;111;111]
mo=imfilter(a1gb,h1,'conv');%application du filtre moyenneur sur l'image a
niveau de gris bruitée
a1gme=medfilt2(a1gb,[3 3]);%application du filtre médian sur l'image a niveau
de gris bruitée
figure(3);
subplot(221);imshow(a1g);subplot(222);imshow(a1gb);subplot(223);imshow(mo);sub
plot(224);imshow(a1gme);
%morphologie mathématique
%dilatation de l'image
I= imread('a1.jpg');
Ib= im2bw (I);
SE= strel('line',11,90);%élément structurant en forme de ligne
SEl = strel('square',5);%élément structurant en forme de ligne
se= offsetstrel('ball',5,5);%élément structurant en forme de boule non plate
j= imdilate(Ib, SE);
figure(1); imshow(j); title('DILATATION');
%erosion de l'image
J= imerode (Ib, SE);
figure(2); imshow(J); title('EROSION');
%ouverture de l'image
J1=imopen (Ib, SE);
figure(3); imshow(J1); title ('OUVERTURE');
%fermeture de l'image
J2=imclose(Ib, SE);
figure(4);imshow(J2); title('FERMETURE');
%meme graphe
figure(4);
subplot(221); imshow(j); title('DILATATION');
subplot(222); imshow(J); title('EROSION');
subplot(223); imshow(J1); title('OUVERTURE');
subplot(224); imshow(j); title('FERMETURE');
%detection des contours
%choisir une image et appliquer tous les filtres de détection des contours
I=imread('a1.jpg');
figure(1);subplot(331); imshow(I); title('Image originale');
Ig = rgb2gray(I);
subplot(332); imshow(Ig);title('image à niveau de gris');
%filtre de détection des contours
Ir=edge(Ig,'roberts'); figure(2); subplot(221); imshow(Ir);title('contour
robert');
Ip=edge(Ig,'prewitt'); figure(2); subplot(222); imshow(Ip);title('contour
prewitt');
Is=edge(Ig,'sobel'); figure(2); subplot(223); imshow(Is);title('contour
sobel');
Ic=edge(Ig,'canny'); figure(2); subplot(224); imshow(Ic);title('contour
canny');
figure(3); imshow(Ir); title('contour robert');
figure(4); imshow(Ip); title('contour prewitt');
figure(5); imshow(Is); title('contour sobel');
figure(6); imshow(Ic); title('contour canny');
%laplacian
figure(7);
c= fspecial('laplacian');
I1 = imfilter (Ig,c); Imshow(I1);