You are on page 1of 2

RGB=imread('tien_xu.

bmp');
RGB=imresize(RGB,[480,480]);
I=rgb2gray(RGB);
BW=im2bw(I,0.5);
figure, imshow(BW);
[X Y]=size(BW);
for i=1:X
for j=1:Y
if BW(i,j)==1;
BW(i,j)=0;
else BW(i,j)=1;
end
end
end
%figure, imshow(BW);
BW1=imfill(BW,'holes');
BW1=bwareaopen(BW1,100);
imshow(BW1);
hold on
[B, L]=bwboundaries(BW1, 'holes');
stats=regionprops(L, 'Area');
allArea = [stats.Area];
b=sort(allArea,'descend');
for i=1: length(allArea)
if allArea(i)< b(5);
allArea(i)=0;
end
end
for i=1: length(B)
boundary=B{i};
m=sprintf('%2.0f',allArea(i));
text(boundary(1, 2), boundary(1, 1), m,'Color', 'b',...
'FontSize', 8, 'FontWeight', 'bold');
end
for i=1:length(allArea)
if allArea(i)==b(1);
tien(i)=5000;
else
if allArea(i)==b(2);
tien(i)=2000;
else
if allArea(i)==b(3);
tien(i)=500;
else
if allArea(i)==b(4);
tien(i)=200;
else
if allArea(i)==b(5);
tien(i)=1000;
else
tien(i)=0;
end
end
end
end
end

end
for i=1: length(B)
boundary=B{i};
m=sprintf('%2.0f',tien(i));
text(boundary(1, 2)+20, boundary(1, 1)+50, m,'Color', 'b',...
'FontSize', 15, 'FontWeight', 'bold');
end
tong =sum(tien);
tong_str=num2str(tong)
set(handles.edit2,'string',tong_str);

You might also like