108 lines
2.8 KiB
Matlab
Executable file
108 lines
2.8 KiB
Matlab
Executable file
donnees;
|
||
|
||
% Param<61>tres de la m<>thode de segmentation :
|
||
T_0 = 1.0;
|
||
alpha = 0.99;
|
||
q_max = 50;
|
||
beta = 2.0;
|
||
|
||
% Estimation des param<61>tres des N classes :
|
||
N = 4;
|
||
nb_tirages = 100000;
|
||
[moyennes, variances, poids] = estimation_non_super(I, N, nb_tirages);
|
||
|
||
% trac<61>/calcul des histogrammes :
|
||
[fxi, x] = ksdensity(I(:), 1:255);
|
||
|
||
fxe = sum(poids ./ sqrt(2 * pi * variances) .* exp(- (x - moyennes).^2 ./ variances / 2));
|
||
|
||
figure;
|
||
plot(x, fxi);
|
||
hold on;
|
||
plot(x, fxe);
|
||
|
||
legend(["image", "MAP"])
|
||
|
||
export_fig(gcf, "saves/exo2hist_" + num2str(N) + "N_" + num2str(beta) + "B_" + num2str(alpha) + "A" + ".png", '-png', '-painters', '-m2');
|
||
|
||
% 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<6E>es (vraisemblance) :
|
||
AD = attache_donnees(I, moyennes, variances);
|
||
|
||
% 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;
|
||
[fimage, map] = rgb2ind(couleurs_pixels, 256);
|
||
imwrite(fimage, map, "saves/exo2mv.png");
|
||
% title(['Maximum de vraisemblance'],'FontSize',20);
|
||
% fprintf('Tapez un caractere pour lancer le recuit simule\n');
|
||
% pause;
|
||
|
||
% Calcul de l'<27>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'<27>nergie par recuit simul<75> :
|
||
temps_affichage = 0.05;
|
||
T = T_0;
|
||
|
||
for q = 1:q_max
|
||
|
||
% Boucle du recuit simul<75> :
|
||
[U, k] = recuit_simule(U, k, AD, T, beta);
|
||
|
||
% Mise <20> 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([num2str(q) + "/" + num2str(q_max) + ", " + num2str(N) + "N, " + num2str(beta) + "B, " + num2str(alpha) + "A"]);
|
||
pause(temps_affichage);
|
||
|
||
if q == 1
|
||
delete("saves/recuit_MAP_" + num2str(N) + "N_" + num2str(beta) + "B_" + num2str(alpha) + "A" + ".gif")
|
||
end
|
||
|
||
export_fig(gcf, "saves/recuit_MAP_" + num2str(N) + "N_" + num2str(beta) + "B_" + num2str(alpha) + "A" + ".gif", '-png', '-painters', '-m2', '-append');
|
||
|
||
% Mise <20> jour de la temp<6D>rature :
|
||
T = alpha * T;
|
||
end
|
||
|
||
% Calcul du pourcentage de pixels correctement class<73>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);
|