You are on page 1of 1

clear all; close all; clc;

original = imread('10x_disperso.png');
I = rgb2gray(original);
threshold = graythresh(I);
bw = im2bw(I,threshold);
[B,L] = bwboundaries(bw);
imshow(label2rgb(L, @jet, [.5 .5 .5]));
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'black', 'LineWidth', 2)
end
total=0;
stats = regionprops(L,'Area');
for k = 1:length(B)
% obtem (X,Y) do contorno k
boundary = B{k};
% A rea do contorno k
area = stats(k).Area;
total =total+area;
valor(k,1)=area;
% o resto bvio, n?
area_string = sprintf('%.0f',area);
text(boundary(1,2)+5,boundary(1,1)+13,area_string,...
'Color','white',...
'FontSize',8,...
'FontWeight','bold',...
'BackgroundColor','black',...
'FontName','Times');
end
title(sprintf('\\fontsize{12}{A rea marcada de %d que %0.2f %% da
rea total %d e a rea vazia %d.}', total-valor(1,1), (100*(total-
valor(1,1)))/total,total,(total-total-valor(1,1))*(-1) ));
hold off

You might also like