Counting winegrape berries using image analysis
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 light-colored individual berries against a dark background. 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 quite well with firm green berries (pre-veraison); modifications to the method will likely be needed if counts of dark berries are done. 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.
- 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/ (these instructions are for version 1.42q of the software)
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). Alternatively, you can attach a dark background to your existing scanner lid.
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 ¾” plastic moulding to make the border; other materials will also work. The underside of the berry tray directly beneath the border is covered with black electrical tape, to prevent the border from appearing in the image. If you would like to try this method and need a berry tray, please contact me.
3) Cover the glass frame with a dark-colored flat board; this provides the dark background in the initial scanned image;
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. If you would like to try using the ImageJ program, you can download practice images at the bottom of this page.
Counting the berries using the ImageJ program:
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 can be helpful. Some berries will now touch; this will be corrected later. Close the "Threshold" window.
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. Note that some scanner programs will automatically crop the image to only show the berries.
6) Choose PROCESS>>BINARY>>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.
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 page for the relationship between square pixels and berry diameter for different scanner resolutions.
If you would like to determine the pixel size of the individual berries that are counted, you can do this readily in the ANALYZE PARTICLES window. Place a check in the box labeled DISPLAY RESULTS:
This will produce a separate window with data values for each berry. The leftmost column is the berry number, and the column labeled "Area" is the number of pixels for each berry. This file can be saved, and opened later with a spreadsheet program.
If you would like to see which berries in the image are counted, in the ANALYZE PARTICLES window select OUTLINES in the SHOW: menu.
This step creates a new image file, in which each counted berry is now displayed as an outline. This image has been expanded below to better show the outlines.
This method, developed in early 2008, is now being used to assist yield forecasting for thousands of acres of winegrapes in California. Employees who previously were tasked with counting berries by hand have reported significant increases in productivity, comfort, and accuracy when using this method. 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 firstname.lastname@example.org
If you are using an old computer which works very slowly in both the scanning and image analysis operations, you can speed it up by using a 100 dpi resolution rather than a 200 dpi resolution as shown above. Just be sure to make the appropriate changes in the settings of the ANALYZE PARTICLES window of ImageJ. See the table at the bottom of this page for guidelines on these settings.
It is generally easier to remove berries from the rachis if the fruit is frozen. If you are working with frozen fruit, you will have to dry off the glass berry tray in between measurements. If you leave the cold sample in contact with the scanner platen for an extended period, it may lead to condensation on the inside of the platen, which will fog the subsequent images. This can be avoided by only placing the berry tray on the scanner to take the image, and removing promptly.
If you have programming skills, all of the steps outlined above in ImageJ can be set up to run automatically by using the built-in macro/script functions. If you set the program up this way, it would allow you to first scan all of your berry sample images, and to then have the ImageJ program process all of the images in one automated operation. This can save considerable time.
You can download the scanned berry images below to practice with ImageJ: