How to count the number of coins in a image using erosion operator?
조회 수: 6 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Evan
2013년 8월 13일
편집: Evan
2013년 8월 13일
You might find Image Analyst's blobs demo to be helpful: http://www.mathworks.com/matlabcentral/fileexchange/25157-image-segmentation-tutorial-blobsdemo
댓글 수: 2
Evan
2013년 8월 20일
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.
Image Analyst
2013년 8월 19일
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
Image Analyst
2013년 8월 20일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!