Counting Australian coins in matlab

2 ビュー (過去 30 日間)
Jamil
Jamil 2013 年 6 月 2 日
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

採用された回答

Image Analyst
Image Analyst 2013 年 6 月 2 日
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 件のコメント
Jamil
Jamil 2013 年 6 月 3 日
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 2013 年 6 月 3 日
Wow thats awesome, thank you so much for your help, I'll read through that code and adapt it to my task, thanks again!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by