UC Delivers  |  ANR News  |  Site Map    
Berry counting
Counting winegrape berries using image analysis
 
Mark Battany, UC Cooperative Extension
mcbattany@ucdavis.edu
805-781-5948
 
Background:
 
The number of grape berries per unit area is a key variable for making accurate crop estimations in mechanically-pruned vineyards.
 
This website describes a novel method for counting grape berries, which may be a suitable replacement for the labor-intensive manual counting which is commonly employed. The advantage of this new method is that it is likely to be much faster, more pleasant to do, and potentially more accurate, as compared to manual counting.

Briefly, in this method loose berries are placed onto a glass-bottomed tray, which is then placed onto a flatbed scanner, and an image is made of the berries; this image will show the individual berries against a background of contrasting color. An image analysis software program is then used to count how many berries appear in the image. It takes much longer to explain it than to do it; the instructions below may look confusing at first, but once you become accustomed to the method it goes very quickly.

Note that the method as described works well with green berries; some modifications will likely be needed if counts of dark berries are done. As I begin to have access to more mature fruit, I will update this site with more information. 

Equipment required:

  • A computer (Windows or Mac), preferably a later model with a high speed processor;
  • A common flatbed scanner; in my work I use a Canon “Canoscan LiDe 90”
  • A homemade berry tray and cover;
  • ImageJ software, downloaded for free from http://rsb.info.nih.gov/ij/
1. setup
 
Steps:

Setting up the equipment:

1)      Install the scanner software on the computer according to manufacturer’s instructions

2)      Remove scanner lid (optional, but makes it easier to work; on the Canon the lid pops off quite easily)

3)      Download and install the ImageJ software on your computer

Making a berry tray:

The removable berry tray serves as a convenient tool to transfer berry samples to and from the scanner; while it may be possible to place berries directly on the platen of the scanner (the glass or plexiglass surface), this is not very practical. The berry tray is simply a sheet of flat clear glass, approximately 1/8” (3mm) thick. The glass is cut to a rectangular shape roughly the same size as the platen of the scanner. In this example, the glass was cut to dimensions of 8 ½” x 12” (21.6cm x 30.5 cm). A border is then glued on one side of the glass plate, around the edge; this forms an enclosed area, which keeps the berries from rolling off of the glass plate and also supports the cover which will be placed on the berry tray when scanning. In this example, I used ¾” aluminum angle stock to make the border; other materials will also work. The underside of the berry tray directly beneath the border was covered with black electrical tape, to block the aluminum from the view of the scanner optics; this may not be necessary.

3. Tray top

 

4. Tray bottom
 

Scanning berries:
 
1)      Remove the berries from the cluster rachis, preferably removing the pedicels from the berries;
 
2)      Place the berries directly onto the berry tray, which is then placed onto the platen;
5. berries in tray

3)      Cover the glass frame with a dark-colored flat board; this provides the dark background in the initial scanned image;

6. scanning

4)      Start the scanner software;
 
5)      Use the following scanner settings:
 
a.      Color Mode: GRAYSCALE
b.      Document Size: PLATEN (or appropriate size for your tray)
c.      Resolution: 200 DPI
d.      Save as file type: JPEG

6)      With the above settings, scan the berry sample;

7)      If you want to see the scanned image, open it in a program such as “Microsoft Office Picture Manager”, or the picture management software which came with your scanner (your scanner software may open the image automatically). You should see an image of light-colored berries on a dark background.

scanned image

 

 Counting the berries using the ImageJ program:

 

1)      Open the ImageJ program; in the explanation below, the text in upper case blue font refers to menu titles in the program;
  
2)      Choose FILE>>OPEN… and select the scanned image file from its folder on your computer; the image will appear as grey colored berries on a black background, as in the image below;
a. first step of scanning
 
3)      Choose IMAGE>>ADJUST>>THRESHOLD...
This step initially turns the image into black background with red berries; in the "Threshold" window there is a pull-down menu; change this from RED to BLACK & WHITE, and the image will turn to black berries on a white background as in the picture below;
     
b. threshold first step

4)   In the "Threshold" window there are two horizontal bars; you can use the mouse cursor to drag the top bar to the left to make the berries become fuller, if necessary; compare the picture below to the one above to see the results. This step may not be necessary, but if the scanned image does not have a distinct color difference between the berries and background this step is helpful. Some berries will now touch; this will be corrected later. Close the "Threshold" window.

c. threshold second step

5)   You should now have a black & white (binary) image showing black berries on a white background. Depending on the design of the berry tray you are using, you will also see some dark patches around the border of the image which are not berries, as in the image below. 

d. finished black and white threshold

6)   Choose PROCESS>>BINARY>>WATERSHED

This important step now places a dividing line between adjacent berries which are touching in the image; this is necessary otherwise the software will count any touching berries as one single 'particle'. This is not a perfect process; some distorted berries may inadvertently be split into two (there is one such case in the image below), but the error rate is quite small. It may appear that numerous berries are still touching in the image below, but this is because the image has been reduced in size to fit this webpage.
e. after watershed

7)      Using the mouse cursor, select a square around the berry sample portion of the image; this shows up as a yellow box in the image below. The analysis in the next step will only evaluate the portion of the image within the yellow box; thus if your berry tray produces a black border in the binary image, this is an easy way to not include that section in the analysis.

f. cursor to select berries

8)   Choose ANALYZE>>ANALYZE PARTICLES to bring up the dialog box shown below.  In this dialog box, place a check in the SUMMARIZE box. For SIZE (PIXEL^2), enter 500-8000; this means that the software will only count those particles which have an area between 500 and 8000 pixels. If this selection is kept with the default setting of 0-INFINITY, the very smallest particles in the image, such as those made by tiny bits of debris, will be counted as berries and will lead to very inaccurate measurements. A value of 500 is roughly equivalent to a 1/8” diameter berry, while 8000 is about ½” diameter; adjust these range values accordingly if the sizes of the berries you are measuring are outside these limits. Note that these settings are for an image scanned with a resolution of 200 dpi; if you scan with a different resolution, you will need to change these pixel size boundaries. See the chart at the bottom of this article for the relationship between square pixels and berry diameter for different scanner resolutions.

g. analyze menu

9)      The results of the particle analysis are displayed in a new “Summary” window (shown overlaying the image below). Under the column labeled ‘Count’ is the total number of berries counted.
g. summary count

In practice, if you are counting berries from a large number of clusters, you will probably find it faster to first do all the scanning as a group, and then follow this with all the image analysis using ImageJ.

This is a new method which is still undergoing testing and development; please check back to this page for updates, tips, suggestions and modifications.

If you try out the method and have any feedback on how it works for you, and suggestions for improvement, I'd like to hear about it. Please email me at mcbattany@ucdavis.edu

 

berry pixels

Tips

Mike and Andrew at French Camp Vineyard use a small cardboard square tube to help keep the berries in the center of the berry tray. The empty tray is first placed on the scanner, the tube is then placed in the middle of the tray, and then the berries poured into the tube and the tube removed. (the tube is shown in the foreground of the photo below).

French camp mod

 

Berry size distribution

A separate page describing how to use the method to estimate berry size distribution is located at this website:

http://cesanluisobispo.ucdavis.edu/Viticulture/Berry_size_distribution.htm