2

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?

enter image description here

lennon310
  • 12,503
  • 11
  • 43
  • 61
Iamcool
  • 1,387
  • 2
  • 12
  • 24

2 Answers2

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:enter image description here

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