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 54 55 56 57 58 59
| [filename, pathname] = uigetfile({'*.jpg;*.tif;*.png;*.gif;*.bmp','All Image Files';...
'*.*','All Files' },'mytitle',...
'C:\Work\myfile.jpg')
f = imread(filename);
% image sur un plan
if (length(size(f))>2)
f=f(:,:,1);% passage de 3 dimensions à 1 ( couleur->niveau de gris)
end
% nombre de bit
k=8;
%taille de la matrice
[M N]=size(f);
f=double(f);
F=double(zeros(M,N));
for p = 0 : M-1
for q = 0 : N-1
for m = 0 : M-1
for n = 0 : N-1
e1=exp((-1i*2*pi*p*m)/M);
e2=exp((-1i*2*pi*q*n)/N);
F(p+1,q+1) =F(p+1,q+1) + f(m+1,n+1)*exp(1i*pi*((m+1)+(n+1))) * e1 * e2;
end
end
end
p/M;
% afiche le pourcentage d'avancement de 0 à 1
end
Famplitude=log2(1+abs(F));% affichage en logarithmique
Famplitude=(Famplitude-min(min(Famplitude)))*255/(max(max(Famplitude))-min(min(Famplitude)));% affichage en logarithmique
Fphase=atan(real(F)./imag(F));
Fphase=(Fphase-min(min(Fphase)))*255/(max(max(Fphase))-min(min(Fphase)));% affichage en logarithmique
fr=double(zeros(M,N));
for m = 0 : M-1
for n = 0 : N-1
for p = 0 : M-1
for q = 0 : N-1
e1=exp((1i*2*pi*p*m)/M);
e2=exp((1i*2*pi*q*n)/N);
fr(m+1,n+1) =fr(m+1,n+1) + (F(p+1,q+1)*exp(-1i*pi*((m+1)+(n+1))) * e1 * e2)/(M*N);
end
end
end
m/M;% afiche le poucentage d'avancement de 0 à 1
end
figure( 'Name','DFT', 'NumberTitle','off', 'color',[0.3137 0.3137 0.5098]);
subplot(221);
imshow(uint8(f));
title('Original');
subplot(222);
imshow(uint8(Famplitude));
title('Amplitue DFT affichage logarithme');
subplot(223);
imshow(uint8(ceil(real(fr))));
title('IDFT reconstitution');
subplot(224);
imshow(uint8(Fphase));
title('Phase DFT affichage logarithme'); |
Partager