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
|
I=imread('pie.jpg');
subplot(2,1,1), imshow(I)
level=graythresh(I);
bw = im2bw(I,level);
if bw(1,1)
bw=~bw;
end
subplot(2,1,2), imshow(bw)
sau=bw;
se = strel('disk',11);
bw = imerode(bw,se);
% Finding the region properties
bw=imfill(bw,'hole');
L = bwlabel(bw);
stats = regionprops(L,'Area','Centroid');
% Counting the dimes by using object sizes
bw=sau;
figure, imshow(bw)
hold on
count = 0;
seuil=200; % par exemple
for i = 1:length(stats)
if stats(i).Area > seuil
plot(stats(i).Centroid(1), ...
stats(i).Centroid(2),'*')
count = count+1;
end
end
title(['There are ' num2str(count) ...
' dimes in this image.']) |
Partager