I have a image similar to below. In that I need to find all red circles and count them. So, I am thinking to use MATLAB R2011a with Image Processing Toolkit for it. How could I possibly extract them?
Asked
Active
Viewed 1,234 times
2
-
1You need to be way more specific for us to help you. What have you tried? What are your requirements? – Hannes Ovrén Dec 24 '13 at 09:24
-
Perhaps first filter all pixels that are red enough, and then blur that a bit? – Dennis Jaheruddin Dec 24 '13 at 10:44
-
do you want to draw all the circles/partial circles, or just count how many red fruits there? – lennon310 Dec 24 '13 at 12:51
2 Answers
1
I can give you a starting point:
v=double(img)/255;
mask = v(:,:,3)+v(:,:,2)-v(:,:,1)<0;
mask = imopen(mask,strel('square',3));
imagesc(min(1,v+cat(3,mask*0,mask*1,mask*0)));axis image
The overlay image looks like:
use RANSAC (as suggested by AdrienNK) on the mask and you'll get the location (and count) of your tomatoes ;-)
-O-

Mercury
- 1,886
- 5
- 25
- 44
-
for instance, if the tomatoes are of green color > "n". Does the mask `v(:,:,3) + v(:,:,1) + v(:,:,2) > n` will do the job? I just tried on an image but its not working – Iamcool Dec 25 '13 at 10:59
-
can you actually explain the second statement you have written clearly.. I think the mask should be something like `v(:,:,1) < 0` – Iamcool Dec 25 '13 at 11:08
-
having red color(1st channel) means high red and almost no green and blue. In other words that the red value is greater than the green and blue colors combined – Mercury Dec 25 '13 at 11:16
0
I suggest you use some filter the points on this picture (as Dennis suggested, filter the ones that aren't red enough). Then you could implement a (Disk) RANSAC (RANdom SAmple Consensus) to find disks within this filtered picture.
RANSAC will use a bit of tuning but then will be able to count quite properly the different objects you are trying to find.
There are a lot of good implementations of RANSAC already done in matlab.

AdrienNK
- 850
- 8
- 19