9

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.

Peter O.
  • 32,158
  • 14
  • 82
  • 96

2 Answers2

4

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.

Alceu Costa
  • 9,733
  • 19
  • 65
  • 83
1

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.

Jeb
  • 3,689
  • 5
  • 28
  • 45
  • Using shape measures in this specific situation may be a little hard because some objects (mangoes) may be partially occluded by leaves. – Alceu Costa Feb 07 '12 at 18:41
  • True; you could use this approach along with yours to validate irregular shapes (obscured mangoes) by going back and getting the hue colour information given the location of the irregular "potential mango" contour. In fact, you could do this for all contours for validation. You'd have to know what range of hue values deem a mango up front though. +1 for your approach! – Jeb Feb 07 '12 at 18:56