You are on page 1of 1

IMG=imread('2.

png');
J = rgb2gray(IMG);I = imresize(J, 0.25);BW= imbinarize(I);
BW2 = bwareaopen(BW, 25);
BW3=bwareaopen(BW, 15);
BW4=bwareaopen(BW, 7);
[B,L,N] = bwboundaries(BW2);
imshow(BW2); hold on;
for k=1:length(B),
boundary = B{k};
if(k > N)
plot(boundary(:,2), boundary(:,1), 'g','LineWidth',2);
else

plot(boundary(:,2), boundary(:,1), 'r','LineWidth',2);


rndRow = ceil(length(boundary)/(mod(rand*k,7)+1));
col = boundary(rndRow,2); row = boundary(rndRow,1);
h = text(col+1, row-1, num2str(L(row,col)));
set(h,'Color',colors(cidx),'FontSize',14,'FontWeight','bold');
end
X=N-1;
end
[B,L,N] = bwboundaries(BW3);
imshow(BW3); hold on;
for k=1:length(B)
boundary = B{k};
if(k > N)
plot(boundary(:,2), boundary(:,1), 'g','LineWidth',2);
else

plot(boundary(:,2), boundary(:,1), 'r','LineWidth',2);


rndRow = ceil(length(boundary)/(mod(rand*k,7)+1));
col = boundary(rndRow,2); row = boundary(rndRow,1);
h = text(col+1, row-1, num2str(L(row,col)));
set(h,'Color',colors(cidx),'FontSize',14,'FontWeight','bold');
end
X2=(N-X-1);
end
[B,L,N] = bwboundaries(BW4);
imshow(BW4); hold on;
for k=1:length(B),
boundary = B{k};
if(k > N)
plot(boundary(:,2), boundary(:,1), 'g','LineWidth',2);
else

plot(boundary(:,2), boundary(:,1), 'r','LineWidth',2);


rndRow = ceil(length(boundary)/(mod(rand*k,7)+1));
col = boundary(rndRow,2); row = boundary(rndRow,1);
h = text(col+1, row-1, num2str(L(row,col)));
set(h,'Color',colors(cidx),'FontSize',14,'FontWeight','bold');
end
X3=(N-X-X2-1);
end

You might also like