%------------------------------------------------
% experiences avec des filtres
%------------------------------------------------

clear all; close all;
load escher;
load map; 

figure('Position',[50 600 560 420]); colormap(map);
image(IM);
disp('image originale et');

[nl,nc] = size(IM);
IMd = double(IM);
IMd = reshape(IMd,1,nl*nc);

hb = fir1(16,0.15);
Sb = filtre0(hb,IMd); Sb = reshape(Sb,nl,nc);
figure('Position',[650 600 560 420]); colormap(map);
image(Sb);
[H,W] = freqz(hb,1);
figure('Position',[1250 600 560 420]); colormap(map);
freqzplot(H,W);
disp('filtrage a phase lineaire passe-bas');
disp('tapez une touche pour continuer'); 
pause; 

hh = fir1(16,0.15,'high');
Sh = filtre0(hh,IMd); Sh = reshape(Sh,nl,nc);
figure(2); image(Sh);
[H,W] = freqz(hh,1);
figure(3); freqzplot(H,W);
disp('filtrage a phase lineaire passe-haut');
disp('tapez une touche pour continuer'); 
pause;

Sc = contraste(Sh,127);
figure(2); image(Sc);
disp('contraste pousse');
disp('tapez une touche pour continuer'); 
pause;

[b,a] = butter(15,0.15);
Snl = filtreii(b,a,IMd); Snl = reshape(Snl,nl,nc);
figure(2); image(Snl);
[H,W] = freqz(b,a);
figure(3); freqzplot(H,W);
disp('filtrage a phase non lineaire passe-haut');
disp('tapez une touche pour continuer'); 
pause;

Sd = deci(reshape(IM,1,nl*nc));
hd = fir1(16,0.5);
Sd = filtre0(hd,Sd);
Sd = reshape(Sd,nl,nc);
figure(2); image(1.1*Sd);
disp('decimation-interpolation + passe-bas');
