1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| %Lecture image raster
[svf,R]=geotiffread('../images/svf.tif');
svf=mat2gray(svf);
%Lecture des centres des objets
[points,R]=geotiffread('../images/points2.tif');
points=double(points);
%Conversion centres en image binaire (points=1, reste=0)
mask=zeros(size(points))
mask(points>0)=1
points=mask
%Obtention des coordonnées (pixels) des centres
[x,y]=ind2sub(size(points),find(points==1));
xy_points=[x(:) y(:)];
%Créer fenêtre de 40x40 pixels et adapter la taille selon la position par
%rapport au bord de l'image
L=max(1,xy_points(:,1)-20);
R=min(xy_points(:,1)+20,size(svf,1));
T=max(1,xy_points(:,2)-20);
B=min(xy_points(:,2)+20,size(svf,2));
%Création d'une cell array contenant autant de matrices que d'objets
for m=1:19;
samples{m}=svf(L(m):R(m),T(m):B(m));
end
%Application de l'algorithme de contour actif
%Création d'une boucle pour enregistrer et convertir une image par objet
for p=1:length(samples)
imwrite(samples{p},sprintf('../images/image%d.pgm',p));
[I,map] = rawread(sprintf('../images/image%d.pgm',p));
I=imresize(I,1);
% Calcul du gradient vector flow sur la fenêtre de 40x40 pixels
disp(' Compute edge map ...');
f = 1-I/255;
f0 = gaussianBlur(f,1);
[px,py] = gradient(f0);
% Début de la déformation
colormap(copper(64));
image(((1-f)+1)*30); axis('square', 'off');
t = 0:1:2;
x = 20+1*cos(t); % c'est ici que je localise l'origine de la déformation
y = 20+1*sin(t);
[x,y] = snakeinterp(x,y,2,0.5);
snakedisp(x,y,'r')
pause(1);
for i=1:12,
[x,y] = snakedeform2(x,y,0.05,0,1, 1, 0.15,px,py,5);
[x,y] = snakeinterp(x,y,0.5,0.2);
snakedisp(x,y,'r')
title(['Deformation in progress, iter = ' num2str(i*5)])
pause(0.1);
end
colormap(gray(64));
image(((1-f)+1)*40); axis('square', 'off');
snakedisp(x,y,'r');
title(['Final result, iter = ' num2str(i*5)]);
% Création d'une image binaire (intérieur/extrérieur) à partir des
% coordonnées x,y et stockage dans un tableau de cellules.
tableau{1,p}=poly2mask(x,y,50,50)
end
% Calcul de la morphométrie
for K=1:19
rprops(K)=regionprops(tableau{1,K},'Area','Eccentricity','MajorAxisLength','MinorAxisLength','Perimeter')
end
Areas=[rprops.Area];
MajorAxisLengths=[rprops.MajorAxisLength];
MinorAxisLengths=[rprops.MinorAxisLength];
[Areas(:),MajorAxisLengths(:),MinorAxisLengths(:)]
clearvars -except rprops |
Partager