How to count the number of coins in a image using erosion operator?

13 views (last 30 days)
in a image after using erosion operator on that image there will be number of coins placed randomly so now we have to find the total number of coins in that image. What are the steps to do this? can we do this by using the area of the coins?
  2 Comments
Anand
Anand on 14 Aug 2013
Provide an image example and tell us what you have tried already.
krishna
krishna on 19 Aug 2013
i have tried using edge detection but not getting the exact logic . the problem is in a image der r some coins we will use erosion operator on that and then we have to count no of coins in that in real time . What logic can we use? for images search in google images u will get one image in which dis operator is used

Sign in to comment.

Answers (2)

Evan
Evan on 13 Aug 2013
Edited: Evan on 13 Aug 2013
  2 Comments
krishna
krishna on 19 Aug 2013
it was partially helpful but i want the the logic used for counting coins in an image . first we have used erosion operator to detect the edges . so wats the steps to count ?
Evan
Evan on 20 Aug 2013
As is done in the tutorial, you can threshold the image, then use regionprops() to obtain all sorts of information about the image. While regionprops can allow you to find much more sophisticated characteristics of your photo, if you just want to count the coins, all you need to do is count the size of the structure returned.
The below snippet of code goes from an RGB image to a count of the number of regions in the thresholded image:
grayPhoto = rgb2gray(myPhoto);
threshold = 0.5; %set this value to one which works for you
maskPhoto = grayPhoto > threshold;
coinLocs = regionprops(maskPhoto,'Centroid');
nCoins = size(coinLocs,1);
fprintf('There are %i coins in this photo',nCoins)
So, basically, it all depends on being able to find a threshold value that robustly separates coins from the background of your image.

Sign in to comment.


Image Analyst
Image Analyst on 19 Aug 2013
I have no idea why you're wanting to do it via morphology instead of with bwlabel() or regionprops() like most people would do it. But if you do you first need to threshold, then call bwulterode() to get a dot for each coin, then sum the image to count the dots. This is not an efficient way to count them, but it is a morphological way if you require that for some reason (like you want to show how slow and inefficient some methods can be).
binaryImage = coinsImage < 128; % or whatever.
dots = bwulterode(binaryImage);
numberOfCoins = sum(dots(:));
  2 Comments
krishna
krishna on 20 Aug 2013
we r doin project our guide asked us to prepare a algorithm for counting coins in a image which contains coins overlapped so we use erosion operator and den we should calculate the no of coins . Which is the efficient method for counting coins in a image?
Image Analyst
Image Analyst on 20 Aug 2013
Overlapped coins should give two dots using bwulterode() because the two overlapped coins will split apart into two pieces as you continually erode it away. So the code I already gave you should still work.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!