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
| N=1; tail_disq=10; seuil=100; petite_aire=25; se = strel('disk',tail_disq);
for k=1:N
fname = sprintf('20060516 rot 50khz 8vpp_t%03d(c1).jpg',k);
I{k} = imread(fname);
background{k} = imclose(I{k},se); I2{k} = imsubtract(background{k},I{k});
level = graythresh(I2{k}); bw{k} = im2bw(I2{k},level);
bw{k}=bwareaopen(bw{k},petite_aire); bw{k} = imclearborder(bw{k});
fill{k} = imfill(bw{k},'holes'); [L{k},NbObjets{k}] = bwlabel(fill{k},8);
b{k} = bwboundaries(fill{k}); rego{k} = regionprops(L{k},'All');
end
for k=1:N
for i=1:NbObjets{k}
cellule{k}(i).x = rego{k}(i).Centroid(1); cellule{k}(i).y = rego{k}(i).Centroid(2);
cellule{k}(i).orientation = rego{k}(i).Orientation;
cellule{k}(i).maj = rego{k}(i).MajorAxisLength; cellule{k}(i).min = rego{k}(i).MinorAxisLength;
x1{k}(i) = cellule{k}(i).x + cellule{k}(i).maj*cos(-cellule{k}(i).orientation*pi/180)/2;
y1{k}(i) = cellule{k}(i).y + cellule{k}(i).maj*sin(-cellule{k}(i).orientation*pi/180)/2;
x2{k}(i) = cellule{k}(i).x - cellule{k}(i).maj*cos(-cellule{k}(i).orientation*pi/180)/2;
y2{k}(i) = cellule{k}(i).y - cellule{k}(i).maj*sin(-cellule{k}(i).orientation*pi/180)/2;
end
end
for k=1 % pour visualiser les objets un par un dans une image donnée
for i=1:NbObjets{k}
bx{i}=zeros(1,4);
bx{i}=rego{k}(i).BoundingBox;
ob{i}=I{k}(bx{i}(2)-.5:bx{i}(2)+bx{i}(4)-.5,bx{i}(1)-.5:bx{i}(1)+bx{i}(3)-.5,:);
figure(i)
imagesc(ob{i}), title(['cellule n° ' num2str(i)])
colormap('gray')
figure(i)
hold on
plot([x1{k}(i) x2{k}(i)],[y1{k}(i) y2{k}(i)])
end
end |
Partager