Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shape Recognition - counting mangoes

I would like to be able to process a close-up image of a mango tree so that I can identify and count the mangoes. A mango is roughly an oval or ellipse shape that is uniquely different from the leaves and branches in the image. I would like to be able to count mangos that might be 20% covered by other objects (but still obvious to the human eye.) I believe there is an algorithm in MatLab that could do this and I would appreciate any help or suggestions.

like image 227
Joy Buchanan Avatar asked Feb 04 '12 03:02

Joy Buchanan


2 Answers

I think that the more robust solution for that problem is to segment by color the mangoes from the background (i.e. tree leaves) and count the number of connected components in the resulting binary image. As btown pointed out, you can get the connected components of a binary image by using the bwconncomp and labelmatrix functions.

To segment the mangoes by color, first convert the image to HSV color space and then perform a binarization using the hue component. I believe that the hue component from the mangoes will be different from other parts of the image. This blog post gives some insight on how to do that in Matlab.

like image 81
Alceu Costa Avatar answered Nov 15 '22 17:11

Alceu Costa


Perhaps you could:

  1. Pre process the image (greyscale/threshold etc.).
  2. Extract all the countours/connected components from the binary image.
  3. Calculate the area and perimeter of each contour/connected component.
  4. Calculate the shape factor/roundness using:

Shape Factor – (4 * PI * Area) / (Perimeter^2). This gives an indication as to the objects shape. Circles have the greatest area to perimeter ratio and this formula will approach a value of 1 for a perfect circle. Squares are around 0.78. A thin thread-like object would have the lowest shape factor approaching 0.

Roundness – (Perimeter^2) / 4 * PI * Area). This gives the reciprocal value of Shape Factor for those that are used to using it. A circle will have a value slightly greater than or equal to 1. Other shapes will increase in value.

So you could approximate a shape factor for an "ideal" mango and see if any of the components lie inside the approximation?

See this for more details.

like image 20
Jeb Avatar answered Nov 15 '22 17:11

Jeb