-
Notifications
You must be signed in to change notification settings - Fork 0
/
TP1.m
53 lines (52 loc) · 1.17 KB
/
TP1.m
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
51
52
53
I=imread('TP01I01.jpg');
I = im2double(I);
%imshow(I)
% spectre de Fourier
F=fft2(I);
S=fftshift(F);
S=ifft2(S);
%L=log2(S);
A=abs(S);
imagesc(A); colormap(gray(256));
% calcul de l'erreur
mse = immse(I, A);
[xI,yI,zI] = size(I);
I2 = I;
n = 1;
valchang =[];
valMSE = [];
while n<(xI/2)-1
nbchang = 0;% nombre de pixels mis a 0
% mettre les n premieres/dernieres
% lignes/colonnes a 0
for y=1:yI
for x=1:xI
if y<n || y>(yI-n) || x<n || x>(xI-n)
I2(x,y)=0;
nbchang = nbchang + 1;
end
end
end
% Calculer la transformée inverse pour produire
% l'image filtrée
F=fft2(I2);
S=fftshift(F);
S=ifft2(S);
A=abs(S);
% Calculer l'Erreur Quadratique Moyenne entre
% l'image de départ et la nouvelle image filtrée
valMSE = [valMSE immse(I, A)];
valchang = [valchang (nbchang / (xI*yI))*100];
n = n+1;
end
[xMSE,yMSE] = size(valMSE);
valMSE= valMSE/max(valMSE)*100;
imagesc(I2);
figure();
x = linspace(1,254,254);
plot(x,valMSE)
title('MSE & number of 0s added')
legend({'y = MSE','y = nb_de_0'},'Location','east')
hold on
plot(x,valchang)
hold off