feat: bcp de commentaires + affichage des cercles en transparence
This commit is contained in:
parent
1cd414d524
commit
e7a390af90
133
TP_maillage.m
133
TP_maillage.m
|
@ -43,14 +43,7 @@ im_mask(end - 5:end, :, :) = 0;
|
||||||
im_mask(:, 1:5, :) = 0;
|
im_mask(:, 1:5, :) = 0;
|
||||||
im_mask(:, end - 30:end, :) = 0;
|
im_mask(:, end - 30:end, :) = 0;
|
||||||
|
|
||||||
% Affichage des images
|
%% Affichage de l'image que l'on souhaite segmenter
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
||||||
% A COMPLETER %
|
|
||||||
% Calculs des superpixels %
|
|
||||||
% Conseil : afficher les germes + les régions %
|
|
||||||
% à chaque étape / à chaque itération %
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
||||||
|
|
||||||
K = 100;
|
K = 100;
|
||||||
m = 0.1;
|
m = 0.1;
|
||||||
|
@ -62,27 +55,14 @@ ind_img = 1;
|
||||||
figure(1);
|
figure(1);
|
||||||
imshow(im(:, :, :, ind_img)); title("Image " + num2str(ind_img));
|
imshow(im(:, :, :, ind_img)); title("Image " + num2str(ind_img));
|
||||||
|
|
||||||
|
%% Calculs des superpixels
|
||||||
|
|
||||||
figure(2);
|
figure(2);
|
||||||
imshow(im(:, :, :, ind_img)); title("Image " + num2str(ind_img));
|
imshow(im(:, :, :, ind_img)); title("Image " + num2str(ind_img));
|
||||||
hold on;
|
hold on;
|
||||||
[germes, image_labelise, E] = super_pixel(im(:, :, :, ind_img), K, m, n, seuil_E, q_max);
|
[germes, image_labelise, E] = super_pixel(im(:, :, :, ind_img), K, m, n, seuil_E, q_max);
|
||||||
|
|
||||||
% subplot(2, 2, 2); imshow(im(:, :, :, 9)); title('Image 9');
|
%% Binarisation de l'image à partir des superpixels
|
||||||
% hold on;
|
|
||||||
% germes = super_pixel(im(:, :, :, 9), K, m, n, q_max);
|
|
||||||
%
|
|
||||||
% subplot(2, 2, 3); imshow(im(:, :, :, 17)); title('Image 17');
|
|
||||||
% hold on;
|
|
||||||
% germes = super_pixel(im(:, :, :, 17), K, m, n, q_max);
|
|
||||||
%
|
|
||||||
% subplot(2, 2, 4); imshow(im(:, :, :, 25)); title('Image 25');
|
|
||||||
% hold on;
|
|
||||||
% germes = super_pixel(im(:, :, :, 25), K, m, n, q_max);
|
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
||||||
% A COMPLETER %
|
|
||||||
% Binarisation de l'image à partir des superpixels %
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
||||||
|
|
||||||
figure(3);
|
figure(3);
|
||||||
R = germes(:, 3);
|
R = germes(:, 3);
|
||||||
|
@ -90,31 +70,37 @@ B = germes(:, 5);
|
||||||
scatter(R, B);
|
scatter(R, B);
|
||||||
hold on
|
hold on
|
||||||
|
|
||||||
|
% définition des coefficients de la droite pour le seuillage
|
||||||
a = (0.7 - 0.1) / (0.6 - 0.2);
|
a = (0.7 - 0.1) / (0.6 - 0.2);
|
||||||
b = 0.1 - a * 0.2;
|
b = 0.1 - a * 0.2;
|
||||||
|
|
||||||
|
% affichage de la droite (pour vérification visuelle du seuillage)
|
||||||
plot([0 1], [b a + b]);
|
plot([0 1], [b a + b]);
|
||||||
|
|
||||||
W = a * R + b - B > 0;
|
W = a * R + b - B > 0;
|
||||||
germes = [germes W];
|
germes = [germes W];
|
||||||
|
|
||||||
%%
|
%% Affichage et amélioration de la binarisation
|
||||||
|
|
||||||
figure(4);
|
figure(4);
|
||||||
tiledlayout(2, 2, 'Padding', 'none', 'TileSpacing', 'compact');
|
tiledlayout(2, 2, 'Padding', 'none', 'TileSpacing', 'compact');
|
||||||
|
|
||||||
bw_img = reshape(germes(image_labelise, 6), size(im, 1), []);
|
bw_img = reshape(germes(image_labelise, 6), size(im, 1), []);
|
||||||
|
|
||||||
|
% affichage de l'image binarisée
|
||||||
nexttile;
|
nexttile;
|
||||||
imshow(bw_img);
|
imshow(bw_img);
|
||||||
|
|
||||||
|
% calcul de la plus grande zone convexe blanche
|
||||||
CC = bwconncomp(bw_img, 4);
|
CC = bwconncomp(bw_img, 4);
|
||||||
bw_img = zeros(size(bw_img));
|
bw_img = zeros(size(bw_img));
|
||||||
bw_img(CC.PixelIdxList{1}) = 1;
|
bw_img(CC.PixelIdxList{1}) = 1;
|
||||||
|
|
||||||
|
% affichage de la plus grande zone convexe blanche
|
||||||
nexttile;
|
nexttile;
|
||||||
imshow(bw_img);
|
imshow(bw_img);
|
||||||
|
|
||||||
|
% calcul des zones convexes noires
|
||||||
bw_img = ~bw_img;
|
bw_img = ~bw_img;
|
||||||
|
|
||||||
CC = bwconncomp(bw_img, 4);
|
CC = bwconncomp(bw_img, 4);
|
||||||
|
@ -123,57 +109,51 @@ bw_img(CC.PixelIdxList{1}) = 1;
|
||||||
|
|
||||||
bw_img = ~bw_img;
|
bw_img = ~bw_img;
|
||||||
|
|
||||||
|
% suppressions des zones convexes noires
|
||||||
nexttile;
|
nexttile;
|
||||||
imshow(bw_img);
|
imshow(bw_img);
|
||||||
|
|
||||||
|
% affichage du masque binaire fourni sur Moodle
|
||||||
bw_img = im_mask(:, :, ind_img);
|
bw_img = im_mask(:, :, ind_img);
|
||||||
|
|
||||||
nexttile;
|
nexttile;
|
||||||
imshow(bw_img);
|
imshow(bw_img);
|
||||||
|
|
||||||
|
%% Squeletisation de l'image
|
||||||
|
|
||||||
figure(5);
|
figure(5);
|
||||||
tiledlayout(2, 2, 'Padding', 'none', 'TileSpacing', 'compact');
|
tiledlayout(2, 2, 'Padding', 'none', 'TileSpacing', 'compact');
|
||||||
|
|
||||||
|
% affichage de l'image
|
||||||
nexttile;
|
nexttile;
|
||||||
imshow(bw_img);
|
imshow(bw_img);
|
||||||
hold on
|
hold on
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
% affichage du contour de la binarisation
|
||||||
% A FAIRE SI VOUS UTILISEZ LES MASQUES BINAIRES FOURNIS %
|
|
||||||
% Chargement des masques binaires %
|
|
||||||
% de taille nb_lignes x nb_colonnes x nb_images %
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
||||||
|
|
||||||
pixel_b = find(bw_img == 1);
|
pixel_b = find(bw_img == 1);
|
||||||
[r, c] = ind2sub(size(bw_img), pixel_b(1));
|
[r, c] = ind2sub(size(bw_img), pixel_b(1));
|
||||||
contour = bwtraceboundary(bw_img, [r c], 'W', 8);
|
contour = bwtraceboundary(bw_img, [r c], 'W', 8);
|
||||||
plot(contour(:, 2), contour(:, 1), 'g', 'LineWidth', 3);
|
plot(contour(:, 2), contour(:, 1), 'g', 'LineWidth', 3);
|
||||||
|
|
||||||
% r = delaunay(contour);
|
% affichage du diagramme de voronoi du contour
|
||||||
% barycentres = (contour(r(:,1),:) + contour(r(:,2),:) + contour(r(:,3),:)) / 3;
|
T = 10; % échantillonage du contour matlab
|
||||||
% scatter(barycentres(:,2), barycentres(:,1));
|
|
||||||
% % triplot(r, contour(:,2), contour(:,1));
|
|
||||||
|
|
||||||
T = 1;
|
|
||||||
[vx, vy] = voronoi(contour(1:T:end, 1), contour(1:T:end, 2));
|
[vx, vy] = voronoi(contour(1:T:end, 1), contour(1:T:end, 2));
|
||||||
|
|
||||||
plot(vy, vx, 'b');
|
plot(vy, vx, 'b');
|
||||||
|
|
||||||
% Selection des segments qui ont leurs extrémités dans l'image
|
% Selection des segments qui ont leurs extrémités dans l'image
|
||||||
ok = vx(1, :) > 1 & vx(1, :) < size(bw_img, 1) & ...
|
ok = vx(1, :) > 1 & vx(1, :) < size(bw_img, 1) & ...
|
||||||
vx(2, :) > 1 & vx(2, :) < size(bw_img, 1) & ...
|
vx(2, :) > 1 & vx(2, :) < size(bw_img, 1) & ...
|
||||||
vy(1, :) > 1 & vy(1, :) < size(bw_img, 2) & ...
|
vy(1, :) > 1 & vy(1, :) < size(bw_img, 2) & ...
|
||||||
vy(2, :) > 1 & vy(2, :) < size(bw_img, 2);
|
vy(2, :) > 1 & vy(2, :) < size(bw_img, 2);
|
||||||
vx = floor(vx(:, ok));
|
vx = floor(vx(:, ok));
|
||||||
vy = floor(vy(:, ok));
|
vy = floor(vy(:, ok));
|
||||||
|
|
||||||
% subplot(2,2,2);
|
% affichage des points de voronoi visibles
|
||||||
nexttile;
|
nexttile;
|
||||||
imshow(bw_img);
|
imshow(bw_img);
|
||||||
hold on
|
hold on
|
||||||
plot(vy, vx, 'b');
|
plot(vy, vx, 'b');
|
||||||
|
|
||||||
% Selection des segments avec les extremités dans la forme
|
% selection des segments avec les extremités dans la forme
|
||||||
|
|
||||||
ind1 = sub2ind(size(bw_img), vx(1, :), vy(1, :));
|
ind1 = sub2ind(size(bw_img), vx(1, :), vy(1, :));
|
||||||
ok1 = bw_img(ind1) > 0;
|
ok1 = bw_img(ind1) > 0;
|
||||||
|
|
||||||
|
@ -184,13 +164,12 @@ ok = ok1 & ok2;
|
||||||
vx = vx(:, ok);
|
vx = vx(:, ok);
|
||||||
vy = vy(:, ok);
|
vy = vy(:, ok);
|
||||||
|
|
||||||
% subplot(2,2,3);
|
% affichage des points de voronoi uniquement dans la forme binaire
|
||||||
nexttile;
|
nexttile;
|
||||||
imshow(bw_img);
|
imshow(bw_img);
|
||||||
hold on
|
hold on
|
||||||
plot(vy, vx, 'b');
|
|
||||||
|
|
||||||
% Remise en forme de vx et vy
|
% mise en forme de vx et vy pour les prochains calculs
|
||||||
vx_ = vx';
|
vx_ = vx';
|
||||||
vx_ = [vx_(:, 1); vx_(:, 2)];
|
vx_ = [vx_(:, 1); vx_(:, 2)];
|
||||||
|
|
||||||
|
@ -199,24 +178,22 @@ vy_ = [vy_(:, 1); vy_(:, 2)];
|
||||||
|
|
||||||
V_ = [vx_ vy_];
|
V_ = [vx_ vy_];
|
||||||
|
|
||||||
% Calcule des rayons
|
% calcul des rayons des points de voronoi au contour
|
||||||
contour_ = contour';
|
contour_ = contour';
|
||||||
R = complex(V_(:, 1), V_(:, 2)) - complex(contour_(1, :), contour_(2, :));
|
R = complex(V_(:, 1), V_(:, 2)) - complex(contour_(1, :), contour_(2, :));
|
||||||
R = abs(R);
|
R = abs(R);
|
||||||
R = min(R, [], 2);
|
R = min(R, [], 2);
|
||||||
R = R';
|
R = R';
|
||||||
|
|
||||||
|
% affichage des cercles
|
||||||
vx_vy = [vy(1, :) vy(2, :); vx(1, :) vx(2, :)]';
|
vx_vy = [vy(1, :) vy(2, :); vx(1, :) vx(2, :)]';
|
||||||
viscircles(vx_vy(1:1:end, :), R(1:1:end));
|
T = 1;
|
||||||
|
viscircles(vx_vy(1:T:end, :), R(1:T:end), 'Color',[0 1 0 0.3]);
|
||||||
|
|
||||||
% Filtrage naif
|
% affichage du squellette
|
||||||
% truc = find(R < 20);
|
plot(vy, vx, 'b');
|
||||||
% truc = mod(truc - 1, length(vx)) + 1;
|
|
||||||
%
|
|
||||||
% vx(:,truc) = [];
|
|
||||||
% vy(:,truc) = [];
|
|
||||||
|
|
||||||
% Filtrage scalaire
|
% Scale Axis Transform
|
||||||
R_scaled = 1.05 * R;
|
R_scaled = 1.05 * R;
|
||||||
|
|
||||||
dist = abs(complex(V_(:, 1), V_(:, 2)) - transpose(complex(V_(:, 1), V_(:, 2))));
|
dist = abs(complex(V_(:, 1), V_(:, 2)) - transpose(complex(V_(:, 1), V_(:, 2))));
|
||||||
|
@ -233,30 +210,16 @@ R = [R(1:length(R) / 2); R(length(R) / 2 + 1:end)];
|
||||||
R(:, mod(c - 1, length(R)) + 1) = [];
|
R(:, mod(c - 1, length(R)) + 1) = [];
|
||||||
R = [R(1, :) R(2, :)];
|
R = [R(1, :) R(2, :)];
|
||||||
|
|
||||||
% subplot(2,2,4);
|
% affichage du squelette filtré par SAT
|
||||||
nexttile;
|
nexttile;
|
||||||
imshow(bw_img);
|
imshow(bw_img);
|
||||||
hold on
|
hold on
|
||||||
plot(vy, vx, 'b');
|
|
||||||
vx_vy = [vy(1, :) vy(2, :); vx(1, :) vx(2, :)]';
|
vx_vy = [vy(1, :) vy(2, :); vx(1, :) vx(2, :)]';
|
||||||
viscircles(vx_vy(1:1:end, :), R(1:1:end));
|
viscircles(vx_vy(1:T:end, :), R(1:T:end), 'Color',[0 1 0 0.3]);
|
||||||
|
plot(vy, vx, 'b');
|
||||||
|
|
||||||
%%
|
%% Reconstruction des points 3D
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
||||||
% A DECOMMENTER ET COMPLETER %
|
|
||||||
% quand vous aurez les images segmentées %
|
|
||||||
% Affichage des masques associes %
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
||||||
|
|
||||||
% Affichage des masques associes
|
|
||||||
% figure;
|
|
||||||
% subplot(2,2,1); ... ; title('Masque image 1');
|
|
||||||
% subplot(2,2,2); ... ; title('Masque image 9');
|
|
||||||
% subplot(2,2,3); ... ; title('Masque image 17');
|
|
||||||
% subplot(2,2,4); ... ; title('Masque image 25');
|
|
||||||
|
|
||||||
% Reconstruction des points 3D
|
|
||||||
X = []; % Contient les coordonnees des points en 3D
|
X = []; % Contient les coordonnees des points en 3D
|
||||||
color = []; % Contient la couleur associee
|
color = []; % Contient la couleur associee
|
||||||
% Pour chaque coupple de points apparies
|
% Pour chaque coupple de points apparies
|
||||||
|
@ -287,7 +250,6 @@ end;
|
||||||
|
|
||||||
fprintf('Calcul des points 3D termine : %d points trouves. \n', size(X, 2));
|
fprintf('Calcul des points 3D termine : %d points trouves. \n', size(X, 2));
|
||||||
|
|
||||||
%affichage du nuage de points 3D
|
|
||||||
figure(6);
|
figure(6);
|
||||||
hold on;
|
hold on;
|
||||||
|
|
||||||
|
@ -298,17 +260,16 @@ end;
|
||||||
axis equal;
|
axis equal;
|
||||||
view(80, -10);
|
view(80, -10);
|
||||||
|
|
||||||
% A COMPLETER
|
%% Tetraedrisation de Delaunay
|
||||||
% Tetraedrisation de Delaunay
|
|
||||||
T = delaunayTriangulation(X(1, :)', X(2, :)', X(3, :)');
|
T = delaunayTriangulation(X(1, :)', X(2, :)', X(3, :)');
|
||||||
|
fprintf('Tetraedrisation terminee : %d tetraedres trouves. \n',size(T,1));
|
||||||
|
|
||||||
% A DECOMMENTER POUR AFFICHER LE MAILLAGE
|
|
||||||
% fprintf('Tetraedrisation terminee : %d tetraedres trouves. \n',size(T,1));
|
|
||||||
% Affichage de la tetraedrisation de Delaunay
|
% Affichage de la tetraedrisation de Delaunay
|
||||||
% figure;
|
% figure(7);
|
||||||
% tetramesh(T);
|
% tetramesh(T);
|
||||||
|
|
||||||
% A DECOMMENTER ET A COMPLETER
|
%% Filtrage de la tetraedrisation de Delaunay
|
||||||
|
|
||||||
% Calcul des barycentres de chacun des tetraedres
|
% Calcul des barycentres de chacun des tetraedres
|
||||||
poids = [1 1 1 1] / 4;
|
poids = [1 1 1 1] / 4;
|
||||||
|
@ -321,8 +282,6 @@ for i = 1:size(T, 1)
|
||||||
C_g(4, i) = 1;
|
C_g(4, i) = 1;
|
||||||
end
|
end
|
||||||
|
|
||||||
% A DECOMMENTER POUR VERIFICATION
|
|
||||||
% A RE-COMMENTER UNE FOIS LA VERIFICATION FAITE
|
|
||||||
% Visualisation pour vérifier le bon calcul des barycentres
|
% Visualisation pour vérifier le bon calcul des barycentres
|
||||||
% for i = 1:nb_images
|
% for i = 1:nb_images
|
||||||
% for k = 1:nb_barycentres
|
% for k = 1:nb_barycentres
|
||||||
|
@ -336,7 +295,6 @@ end
|
||||||
% end
|
% end
|
||||||
% end
|
% end
|
||||||
|
|
||||||
% A DECOMMENTER ET A COMPLETER
|
|
||||||
% Copie de la triangulation pour pouvoir supprimer des tetraedres
|
% Copie de la triangulation pour pouvoir supprimer des tetraedres
|
||||||
tri = T.ConnectivityList;
|
tri = T.ConnectivityList;
|
||||||
% Retrait des tetraedres dont au moins un des barycentres
|
% Retrait des tetraedres dont au moins un des barycentres
|
||||||
|
@ -370,12 +328,13 @@ end
|
||||||
triBis = tri(to_save, :);
|
triBis = tri(to_save, :);
|
||||||
nb_barycentres = length(to_save);
|
nb_barycentres = length(to_save);
|
||||||
|
|
||||||
% A DECOMMENTER POUR AFFICHER LE MAILLAGE RESULTAT
|
|
||||||
% Affichage des tetraedres restants
|
|
||||||
fprintf('Retrait des tetraedres exterieurs a la forme 3D termine : %d tetraedres restants. \n', size(T, 1));
|
fprintf('Retrait des tetraedres exterieurs a la forme 3D termine : %d tetraedres restants. \n', size(T, 1));
|
||||||
figure(7);
|
|
||||||
|
figure(8);
|
||||||
tetramesh(triBis, T.Points);
|
tetramesh(triBis, T.Points);
|
||||||
view(80, -10);
|
view(80, -10);
|
||||||
|
|
||||||
% Sauvegarde des donnees
|
% Sauvegarde des donnees
|
||||||
save donnees;
|
save donnees;
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue