TP-probleme-inverse-3D/TP6/exercice_1.m
2023-06-25 16:38:01 +02:00

72 lines
1.7 KiB
Matlab

clear;
close all;
taille_ecran = get(0,'ScreenSize');
L = taille_ecran(3);
H = taille_ecran(4);
I_max = 255;
pas_decimation = 1;
% nom_image = 'Beethoven.png';
nom_image = "Lena.png"
nom_masque = 'Beethoven_masque.png';
nb_iterations = 500;
epsilon = 1e-6;
% Lecture et affichage de l'image :
I = imread(nom_image);
I = I(1:pas_decimation:end,1:pas_decimation:end,:); % Décimation de l'image
I = double(rgb2gray(I))/I_max;
[nb_lignes,nb_colonnes] = size(I);
figure('Name','Resolution iterative du SfS','Position',[0,0,0.5*L,0.7*H]);
subplot(2,2,1);
imagesc(I);
axis equal;
axis off;
hold on;
colormap gray;
title('Image','Interpreter','Latex','Fontsize',20);
drawnow;
% Lecture du masque :
% masque = imread(nom_masque);
% masque = masque(1:pas_decimation:end,1:pas_decimation:end); % Décimation du masque
% masque = masque>0;
masque = ones(size(I));
subplot(2,2,2);
imagesc(masque);
axis equal;
axis off;
hold on;
colormap gray;
title('Masque','Interpreter','Latex','Fontsize',20);
drawnow;
% Membre droit de l'équation eikonale (attention aux troncations) ;
f = sqrt(1./(min(0.95,max(I,0.05)).^2)-1);
% Initialisation de la solution :
z = zeros(nb_lignes,nb_colonnes);
% Schéma itératif :
for k = 1:nb_iterations
% Sauvegarde de l'itération courante :
z_k_moins_1 = z;
% Pas de l'itération :
z = lax_friedrichs(z_k_moins_1,f,masque);
% Affichage du résultat courant :
relief_et_image(z,k);
pause(0.001);
% Test de convergence :
if (norm(z_k_moins_1(masque>0)-z(masque>0))./norm(z(masque>0))<epsilon)
break;
end
end
% Simulation d'un éclairage tournant :
figure('Name','Reeclairage du relief reconstruit','Position',[0.5*L,0,0.5*L,0.7*H]);
reeclairage(z);