Counting Australian coins in matlab

2 visualizzazioni (ultimi 30 giorni)
Jamil
Jamil il 2 Giu 2013
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

Risposta accettata

Image Analyst
Image Analyst il 2 Giu 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 Commenti
Jamil
Jamil il 3 Giu 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 il 3 Giu 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!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Image Processing Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by