Course Home
Administration
Syllabus
References
Lecture Notes
Readings
Assignments
Projects
Resources


Comments? Idea?























































































































































































































































































































































Detecting grapes in vineyard images

Final project by

Sivan Radt


Introduction

Image segmenting is a tricky one. It's a blurry concept, and even for simple images, you can find quite a few ways to segment them. For example:

QUEEN%20AND%20HORSE.jpg

You can look at it as an image with 4 segments: there's her majesty, the horse, the horseman and the wall behind.
But!  How about segmenting the queen to 3 parts: Her fashionable hat, her face and her coat?
Is the horseman's glove a segment?
what about the horse – how many segments do you see in it?

So it's a bit Ill-defined.

In the grape detection project we were asked to segment an image taken in a vineyard into two segments: One is the grapes, the other – all the rest.
Sounds easy?  Well, not really.  It's a problem that still doesn't have an accurate solution – Researchers and scientists in the field of computational vision still work on it.

Still it's an interesting question. Let us try and answer it.

Approach and Method

First I had to define the properties which I wanted to segment by, the ones that separate grapes from the rest of the image:

Color: green
Shape: circle
Size: small
Texture: smooth and round
Special features: Clusters

I found on Matlab's fileexchange the function HoughCircles_grd. It's a nice function that detects circles in images, even if they're not perfect. So I thought I could use it.

Problem is, when you try to find circles on an image as is, you'd probably get bad results. The image has to be refined to achieve more accurate results.

 

To do that, I used several tools:

 

1.      Segmentation via thresholding – Global thresholding

Choosing thresholds for the whole image and using them on each pixel to segment.

One way to do it is:

 

for (i=1:length)

    for (j=1:width)

             S1 (i, j) = p * floor(S1(i,j)/p);

    end

end

 

After this, I got rid of mid-shades, and got a small number of big segements, depends on d: the bigger p is, the smaller the number of segments achieved.

(I didn't use it in the end)

 

2.      Segmentation via thresholding – Adaptive local thresholding

This segmentation method chooses the threshold according to the pixel's environment. It's more accurate and smart than the global segmentation, also you don't need to guess the thresholds.

This is also a nice piece a code from Matlab's fileexchange: the function adaptivethreshold written by Guanglei Xiong. Thanks, Guanglei!

 

3.      Edge detection

Sometimes used Canny's algorithm, sometimes Prewitt's.

Ok, so let's take an image from our given database and try to segment it.

slika1916

Here we can see some interesting things:
The very light area doesn't belong to the grapes, it's part of the ground – so we can immediately filter it out.
Also we can filter all the parts that have a high Red/Green ration, such as the ground, the trunk and the branches – more than 1.2 is enough.

To make things easier, we'll convert it to grayscale:

And remove the white area:

And the red area:

Here, we've just begun and already filtered out about half of the image. But it's just luck, most of the pictures don't have "burnt up" areas, or "too red" areas.

See the small gray dots in the blackened area? We can filter them. A simple filter that reduces this kind of "noise" in an image (Salt & Pepper) is medfilt2.

If we try to find circles in the image now, we'll get:


So we need some more image processing. Let's try to segment the image using Guanglei's function, and then smooth it a bit:

It's almost what we need. How will we reach the segment in the upper-left corner? Let’s smooth this image:

This is close enough, and if we try to find circles in the picture now, we get:

When the accurate segmentation is:

Quite nice, no?

 

Results

If we try to run the segmentation on another picture, we get:

slika927

After segmentation:

When the accurate segmentation is:

Conclusions

When we tried our function that was made according to the properties of one picture, we discovered that the results aren't as great as in the first image. It proves that each picture will get the best segmentation with different actions and parameters.

How will we know which actions and parameters? I don't know if it can be done automatically, or in advance at all – and that's why it's a tough question.

 

Additional Information

Make sure that all the downloadable files are included in your zip file!!

References