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 CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by