Counting Australian coins in matlab
3 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
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
More Answers (0)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!