87 lines
2.3 KiB
Mathematica
87 lines
2.3 KiB
Mathematica
|
donnees;
|
|||
|
|
|||
|
% Param<EFBFBD>tres de la m<EFBFBD>thode de segmentation :
|
|||
|
T_0 = 1.0;
|
|||
|
alpha = 0.9;
|
|||
|
q_max = 50;
|
|||
|
beta = 2;
|
|||
|
|
|||
|
% Estimation des param<EFBFBD>tres des N classes :
|
|||
|
N = 4;
|
|||
|
[moyennes,variances] = estimation(I,N,couleurs_classes);
|
|||
|
|
|||
|
% Permutation des classes pour pouvoir calculer le pourcentage de bonnes classifications :
|
|||
|
[~,indices] = sort(moyennes,'ascend');
|
|||
|
moyennes = moyennes(indices);
|
|||
|
variances = variances(indices);
|
|||
|
couleurs_classes = couleurs_classes(indices,:);
|
|||
|
|
|||
|
% Calcul de l'attache aux donn<EFBFBD>es (vraisemblance) :
|
|||
|
AD = attache_donnees(I,moyennes,variances);
|
|||
|
export_fig(gcf, 'saves/expert_BW.png', '-png','-painters','-m2');
|
|||
|
|
|||
|
% Initialisation des classes :
|
|||
|
couleurs_pixels = zeros(nb_lignes,nb_colonnes,3);
|
|||
|
[U,k] = min(AD,[],3);
|
|||
|
for i = 1:nb_lignes
|
|||
|
for j = 1:nb_colonnes
|
|||
|
couleurs_pixels(i,j,:) = couleurs_classes(k(i,j),:);
|
|||
|
end
|
|||
|
end
|
|||
|
% close all;
|
|||
|
figure;
|
|||
|
% subplot(1,2,2);
|
|||
|
imagesc(couleurs_pixels);
|
|||
|
axis equal;
|
|||
|
axis off;
|
|||
|
title(['Maximum de vraisemblance'],'FontSize',20);
|
|||
|
[fimage, map] = rgb2ind(couleurs_pixels, 256);
|
|||
|
imwrite(fimage, map, "saves/exo1mv.png");
|
|||
|
% fprintf('Tapez un caractere pour lancer le recuit simule\n');
|
|||
|
% pause;
|
|||
|
|
|||
|
% Calcul de l'<EFBFBD>nergie initiale :
|
|||
|
for i = 1:nb_lignes
|
|||
|
for j = 1:nb_colonnes
|
|||
|
U(i,j) = U(i,j)+beta*regularisation(i,j,k,k(i,j));
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
% Minimisation de l'<EFBFBD>nergie par recuit simul<EFBFBD> :
|
|||
|
temps_affichage = 0.1;
|
|||
|
T = T_0;
|
|||
|
energies_plot = zeros(q_max, 1);
|
|||
|
for q = 1:q_max
|
|||
|
|
|||
|
% Boucle du recuit simul<EFBFBD> :
|
|||
|
[U,k] = recuit_simule(U,k,AD,T,beta);
|
|||
|
energies_plot(q) = sum(U(:));
|
|||
|
% Mise <EFBFBD> jour de l'affichage :
|
|||
|
for i = 1:nb_lignes
|
|||
|
for j = 1:nb_colonnes
|
|||
|
couleurs_pixels(i,j,:) = couleurs_classes(k(i,j),:);
|
|||
|
end
|
|||
|
end
|
|||
|
imagesc(couleurs_pixels);
|
|||
|
axis equal;
|
|||
|
axis off;
|
|||
|
title(['Recuit simule : iteration ' num2str(q) '/' num2str(q_max)]);
|
|||
|
pause(temps_affichage);
|
|||
|
|
|||
|
[fimage, map] = rgb2ind(couleurs_pixels, 256);
|
|||
|
export_fig(gcf, "saves/exo1.gif", '-png', '-painters', '-m2', '-append');
|
|||
|
|
|||
|
% Mise <EFBFBD> jour de la temp<EFBFBD>rature :
|
|||
|
T = alpha*T;
|
|||
|
end
|
|||
|
|
|||
|
% Calcul du pourcentage de pixels correctement class<EFBFBD>s :
|
|||
|
pixels_correctement_classes = find(k==k_exact);
|
|||
|
nb_pixels = nb_lignes*nb_colonnes;
|
|||
|
fprintf('Pixels correctement classes : %.2f %%\n',100*length(pixels_correctement_classes(:))/nb_pixels);
|
|||
|
|
|||
|
figure;
|
|||
|
plot(energies_plot);
|
|||
|
% title(['Recuit simule : <EFBFBD>nergies']);
|
|||
|
axis square;
|
|||
|
export_fig(gcf, 'saves/exo1energie.png', '-png','-painters','-m2');
|