clear all, close all;

% exemple d'image de travail:
I = double(rgb2gray(imread('house.tiff')));

figure, imshow(uint8(I));
title('image originale')


% avec filtre gaussien

sigma=1;
G=fspecial('gaussian',6*sigma,sigma);
figure, imagesc(G), colorbar
title('filtre gaussien');
figure, surf(G);
title('filtre gaussien');

I_smooth=imfilter(I,G);

figure, imshow(uint8(I_smooth));
title('image ''smooth''');

figure, imagesc(log(abs(fftshift(fft2(I))))); colorbar; colormap(gray);
title('spectre de l''image originale');

figure, imagesc(log(abs(fftshift(fft2(I_smooth)))),[0 16]); colorbar; colormap(gray);
title('spectre de l''image ''smooth''');

I_edges_G = I-I_smooth;
figure, imagesc(I_edges_G), colormap(gray), colorbar;
title('edges');

figure, imagesc(log(abs(fftshift(fft2(I_edges_G)))),[0 16]); colorbar; colormap(gray);
title('spectre de l''image des contours');

k=0.7;
I_unsharp = I + k*I_edges_G;
figure, imshow(uint8(I_unsharp))
  title('resultat du filtre unsharp mask (Gaussien)');


k=0.9;
I_noise = I + 5*randn(size(I)) ;
I_edges_noise=I_noise-imfilter(I_noise,G);
I_unsharp = I_noise + k*I_edges_noise;

figure, imshow(uint8(I_noise))
  title('image originale bruitée');
figure, imshow(uint8(I_unsharp))
  title('resultat du filtre unsharp mask (Gaussien), cas bruité');


  
% avec la fonction unsharp_mask:
close all;
figure; imshow(uint8(I)); title('Image originale');
k=0.9; sigma=1; Ima_UM=unsharp_mask(I,k,sigma);
figure; imshow(uint8(Ima_UM)); title(['k= ',num2str(k),' sigma= ',num2str(sigma)]);
k=2.5; sigma=1; Ima_UM=unsharp_mask(I,k,sigma);
figure; imshow(uint8(Ima_UM)); title(['k= ',num2str(k),' sigma= ',num2str(sigma)]);
k=0.9; sigma=10; Ima_UM=unsharp_mask(I,k,sigma);
figure; imshow(uint8(Ima_UM)); title(['k= ',num2str(k),' sigma= ',num2str(sigma)]);
k=2.5; sigma=10; Ima_UM=unsharp_mask(I,k,sigma);
figure; imshow(uint8(Ima_UM)); title(['k= ',num2str(k),' sigma= ',num2str(sigma)]);

 
% images couleur

clear all, close all;
% choisir une image:
I=imread('house.tiff');
I=imread('splash.tiff');
I=imread('jellybeans.tiff');

sigma=2;
k=1.5;
G=fspecial('gaussian',6*sigma,sigma);
I_edges=I-imfilter(I,G);
I_unsharp = I + k*I_edges;
figure; imshow(uint8(I)); title('image originale');
figure; imshow(uint8(I_unsharp)); title('resultat du filtre unsharp mask RGB');

% alternative: on accentue uniquement la composante de luminance

J=rgb2lab(I);
L=J(:,:,1);
L_edges=L-imfilter(L,G);
L_unsharp = L + k*L_edges;
J(:,:,1)=L_unsharp;
I_unsharp=lab2rgb(J);
figure; imshow(uint8(I)); title('image originale');
figure; imshow(I_unsharp); title('resultat du filtre unsharp mask Luminance');



% local contrast enhancement
% cherchez les termes "brouillard" ou "fog" dans Google Image

clear all, close all;

% testez successivement les images suivantes

I = imread('brouillard.jpg');
sigma=100;
k=0.8;

I = imread('brouillard2.jpg');
sigma=50;
k=0.5;

I = imread('IMGA2155.jpg');
sigma=50;
k=0.5;

I = imread('fog-03.jpg');
sigma=150;
k=1;

J=rgb2lab(I);
G=fspecial('gaussian',6*sigma,sigma);
L=J(:,:,1);
L_edges=L-imfilter(L,G);
L_unsharp = L + k*L_edges;
J(:,:,1)=L_unsharp;
I_unsharp=lab2rgb(J);
figure, imshow(uint8(I))
  title('image originale')
figure, imshow(I_unsharp)
  title('resultat du local contrast enhancement')



