Counting Australian coins in matlab

3 views (last 30 days)
Hi, I need to write a function that calculates how many coins are in a picture and determines there combined value, I have the following code that works for a stock image, but I cant seem to apply it to work with an image containing Australian coins, such as this:
Here is the current code I have:
_______________________________________________________
coin1 = im2bw(imread('coins.png'));
coin2 = imfill(coin1,'holes');
[L Ne]=bwlabel(double(coin2));
prop=regionprops(L,'Area','Centroid');
total=0;
imshow(imread('coins.png'));hold on
for n=1:size(prop,1)
doll=prop(n).Centroid;
X=doll(1);Y=doll(2);
if prop(n).Area>2000
text(X-10,Y,'$1')
total=total+1;
else
total=total+2;
text(X-10,Y,'$2')
end
end
number = n
dollar = total
hold on
title(['Dollars: $',num2str(dollar),' ', 'Number of coins:',num2str(n)])
_________________________________________________________________
Any help would be appreciated, thanks

Accepted Answer

Image Analyst
Image Analyst on 2 Jun 2013
See my demo where I do the same thing with the US coins supplied in the standard MATLAB demo image: http://www.mathworks.com/matlabcentral/fileexchange/25157-image-segmentation-tutorial-blobsdemo I find 5 cent and ten cent coins. Of course from that point it's a simple matter to add up the value of the coins.
Just a quick glance looks like your code should work as long as there are only two type of coins and those with area more than 2000 all have the same value and those with area less than that all have the same value. What is not working?
  11 Comments
Jamil
Jamil on 3 Jun 2013
Im not sure, I assume the coins are less than 2000 pixels, but then i cant imagine why it worked fine for my stock image, sorry like i said im new to matlab and im multitasking this task with a bunch of others, ive found this to be very confusing im not sure what i need to change in the code
Jamil
Jamil on 3 Jun 2013
Wow thats awesome, thank you so much for your help, I'll read through that code and adapt it to my task, thanks again!

Sign in to comment.

More Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!