Vous êtes sur la page 1sur 5

TP3: Le Filtrage

Ex1:
clear all;
close all;
%creer une matrice de 9 lignes et 9 colonnes de zero
H1=zeros(9,9);
%à partir de ligne 4 à ligne 6 toutes les colonnes 4 jusqu'a
colonne 6 sont des uns
H1(4:6,4:6)=ones(3,3);
h=fsamp2(H1);
freqz2(h,[9 9]);
[f1,f2]=freqspace([9 9]);
freqz2(h,[32 32]);
[x y]=meshgrid(f1,f2);
figure(1), mesh(x,y,h),title( 'réponse fréquentielle' );

(Figu r e1 )

Ex2:

clear all;
close all;
% création de filtre h1, h2 et h3
h1=-ones(3,3);
h1(2,2)=8;
h3=1/9*ones(3,3);
h2=-ones(3,3);
h2(2,2)=9;
% lecture de l'image
I=imread('moon.tif');
% application d'un bruit
f=imnoise(I,'gaussian', 0.02);
% application de filtre h1
F1=filter2(f,h1);
% application de filtre h2
F2=filter2(f,h2);
% Application de filtre h3
F3=filter2(f,h3);
% Affichage de 3 images
figure(1),subplot(1,5,1),imshow(I),title( 'image net');
figure(1),subplot(1,5,2),imshow(f),title( 'image bruité');
figure(1),subplot(1,5,3),imshow(F1),title( 'Filter h1');
figure(1),subplot(1,5,4),imshow(F2),title( 'Filter h2');
figure(1),subplot(1,5,5),imshow(F3),title( 'Filter h3');

(Figu r e 2)

Ex3:

clear all;
close all;
%les trois filtres
h1=-ones(3,3);
h1(2,2)=8;
h2=-ones(3,3);
h2(2,2)=9;
h3=(1/9)*ones(3,3);
% lecture de l'image
I = imread('moon.tif','tif');
% application d'un bruit
f = imnoise(I,'gaussian');
% application des filtre
F1 = imfilter(f,h1);
F2 = imfilter(f,h2);
F3 = imfilter(f,h3);
% affichage de l'image filtrée
figure(1);
subplot(1,5,1);imshow(I),title( 'Image net');
subplot(1,5,2);imshow(f),title( 'Image bruité');
subplot(1,5,3);imshow(F1),title( 'Filtre h1');
subplot(1,5,4);imshow(F2),title( 'Filtre h2');
subplot(1,5,5);imshow(F3),title( 'Filtre h3');

(Figu r e 3)

Ex4:
% création des filtres
h1=-ones(3,3);
h1(2,2)=8;
h2=-ones(3,3);
h2(2,2)=9;
h3=(1/9)*ones(3,3);
% lecture de l'image
I=imread('coins.png' );
% application d'un bruit
b = imnoise(I,'gaussian');
% application d'un filtre
F1 = imfilter(b,h1);
m1 = medfilt2(F1);
F2 = imfilter(b,h2);
m2 = medfilt2(F2);
F3 = imfilter(b,h3);
m3 = medfilt2(F3 );
% affichage de l'image filtrée
figure(1);
subplot(1,4,1);imshow(I),title( 'Image net');
subplot(1,4,2);imshow(b),title( 'Bruit gaussian');
subplot(1,4,3);imshow(F1),title( 'Imfilter h1' );
subplot(1,4,4);imshow(m1),title( 'medfilter h1' );
figure(2);
subplot(1,4,1);imshow(F2),title( 'Imfilter h2' );
subplot(1,4,2);imshow(m2),title( 'medfilter h2' );
subplot(1,4,3);imshow(F3),title( 'Imfilter h3' );
subplot(1,4,4);imshow(m3),title( 'medfilter h3' );

(Figu r e 5)
(Figu r e 6)

Vous aimerez peut-être aussi