Count Coin Values in Image using MATLAB

As the first step, I am going to read the image.
             img = imread('F:/Academic Video/MC/PracticalAssignment_I/Coins.jpg');

As the second step, I am going to crop the image.
            img1 = img(700:2500,400:1950,:);
As the third step, I am going to convert the image into black and white
            bw = im2bw(img1);
As the fourth step, I am going to convert the background color into black and object color into white.
            bw = ~bw;
As the fifth step, I am going to enhance the objects.
            se = strel('disk',50);
            img2 = imdilate(bw,se);


            img2 = imerode(img2,se);
            se = strel('disk',60);
            img2 = imerode(img2,se);
As the sixth step, I am going to get the count of coins.
            [L N]=bwlabel(img2);
            N
            N =

                   8
As the seventh step, I am going to label the coins. (text(X coordination ,Y coordination,value))

t = [text(344,1039,'1'),
text(300,712,'2'),text(475,283,'10'),text(596,1513,'2'),text(785,766,'2'),text(1055,322,'5'),
text(1142,1510,'10'),text(1172,913,'1')];



See the label in the figure without using imshow(img2).

As the last step, I can get the summation of the values.
      sum =0;
      for x=1:N
      sum = sum+(str2num(t(x).String));
     end
     sum
     sum =
               33

Comments

Popular posts from this blog

C# Analog Clock

Basic Prolog (List)

SOLID Principles