Welcome to the Harris Geospatial product documentation center. Here you will find reference guides, help documents, and product libraries.

Count Crops

Count Crops

Crop Counting and Metrics Tutorial

Use the Count Crops tool to locate and count crops in high-resolution, single-band imagery. It creates a classification image with circles that represent crops.

This tool is part of ENVI Crop Science, which requires a separate license and installation. You can also write a script to perform crop counting using the ENVIAgCropCount function.

See the following sections:

Before You Begin

You should spatially subset the image to include only your area of interest. If using the Count Crops tool for a single agricultural field, create a spatial subset that includes the extent of the field, or mask out the rest of the image outside of the field extent. See Example of Subsetting by ROI in the Hotspot Analysis topic for instructions on creating a spatial subset from a region of interest (ROI).

The Count Crops tool looks for bright, circular shapes. Rather than provide a multispectral image as input, you should provide a single-band image that makes the crops bright compared to the image background. Here are some examples:

Spectral Indices

You can create a spectral index image that highlights healthy, green vegetation. Use the Spectral Indices tool with a multispectral image as input, and create an image where each band is a different spectral index. Use the Band Animation tool to review each band (index). Then use the File > Save As > Save As (ENVI, NITF, TIFF, DTED) menu option to create a spectral subset of the band you are interested in, and save it to an ENVI-format file. Use the spectral index image as input to the Count Crops tool. The following is an example of a Simple Ratio index image that highlights strawberry crops:


Data should be in units of reflectance prior to creating spectral indices. Most UAV and airborne sensors used for precision agriculture measure reflectance in visible and near-infrared wavelengths, so no further calibration should be required. Some spectral indices (for example, Anthocyanin Reflectance Index 1 and 2) require the data to be in units of reflectance, ranging from 0 to 100 percent (scaled from 0 to 1). Use the ENVI Spectral Math tool if necessary to scale the reflectance data to this range. See the Spectral Indices topic in ENVI Help for more information.

Inverted Green Band

Use the Enhance Crops tool (included with ENVI Crop Science) to create an image of inverted green band values. Then pass the result to the Count Crops tool. The following image shows an example with walnut trees. The scale and resolution of this image is different than the previous example.

Elevation Data

If you have access to high-resolution point cloud data, you can use the ENVI LiDAR application to create a digital surface model (DSM) and digital elevation model (DEM). Subtract the DEM from the DSM to create a canopy height image to use as input to the Count Crops tool. This is an effective way to highlight tall crops and trees. You can optionally threshold the canopy height image to identify crops that fall within a specific height range, before running the Count Crops tool. This helps to eliminate false positives where weeds are present. The following image shows an example of a canopy height image of citrus crops:

Run the Count Crops Tool

The Count Crops tool has a number of parameters that you must experiment with to obtain the best results. Follow these steps to run the Count Crops tool:

  1. From the Toolbox, select Crop Science > Count Crops.
  2. Select an Input Raster. See Before You Begin for guidelines on creating and selecting an input image.
  3. Enter a value for Minimum Crop Diameter. If the input raster has a spatial reference, enter the diameter value in meters. Otherwise, enter the number of pixels.
  4. Tip: You can use the Mensuration tool in the ENVI toolbar to measure the diameter of individual crops.

  5. Enter a value for Maximum Crop Diameter. If the input raster has a spatial reference, enter the diameter value in meters. Otherwsie, enter the number of pixels.
  6. The Count Crops tool works best when the minimum and maximum crop diameters do not differ greatly in size. For example, a range of 1 to 4 meters will produce better results than a range of 1 to 16 meters. If your area of interest has a wide range of crop diameters, consider splitting the area into separate images to process, each with a similar range of crop diameters.

  7. Optional: Enter the Number of Increments to use when searching crops. This number includes the minimum and maximum diameters. The default value is 5. For example, if the minimum crop diameter is 1 meter and the maximum crop diameter is 5 meters, setting the number of increments to 5 will search for crops of approximately 1, 2, 3, 4, and 5 meters. Experiment with different values, along with Minimum Crop Diameter and Maximum Crop Diameter, to see what produces the best results.
  8. The Count Crops tool finds crops up to half of the specified increment outside of the minimum and maximum diameters.

  9. Optional: Enter a Gaussian Smoothing Factor. This is the fraction of the maximum search diameter at which an additional Gaussian smoothing occurs. It helps to reduce noise in the final result. The default value of 0.5 is suitable for many applications, but other datasets produce better results with a value of 0. Experiment with different values if needed.
  10. Optional: Enable the Include Edges option if you want to count partial crops touching the edges of the image or any masked area that surrounds the area to be counted. You should enable this option when applying a mask within the area being counted, for example, when masking out non-vegetation pixels. The default is No. The following image illustrates masked edges and image edges:
  11. Experiment with Include Edges, along with different values for Minimum Crop Diameter, Maximum Crop Diameter, and Allowable Crop Overlap, to get the most accurate results along the edges of your dataset.

  12. Optional: Enter a percentage for Allowable Crop Overlap. This is the percentage of allowable overlap between two adjacent crops before one of them is removed from consideration. The default value is 50%. Enter smaller values if the crops are distinctly separated from one another.
  13. Optional: Enter an Intensity Threshold value. This is the fraction of the maximum crop intensity, below which crop detections will be removed. If the crop-count result includes false positives, experiment with different intensity threshold values to remove the false positives.
  14. Optional: Select an output filename and location for the Output Crops File. This is a JSON-format text file that specifies the locations of the crop centers. This can be used as input for tools such as Crop Metrics.
  15. Enable the Fill Raster Crops option to display filled circles instead of outlines in the classification result. The default value is No.
  16. Select an output filename and location for the Output Crops Raster. This is a classification raster showing circles that represent individual crops.
  17. Select the Display result option to display the output image when processing is complete.
  18. Enable the Preview check box to see a preview of the settings before you click OK to process the data. The preview is calculated only on the area in the Image window and uses the resolution level at which you are viewing the image.
  19. Click OK. ENVI adds the resulting output to the Data Manager and Layer Manager, and it displays the output in the Image window. The result is a classification image that shows the locations of individual crops, for example:

To edit the name and color of the Crops class, right-click on the Classes folder in the Layer Manager and select Edit Class Names and Colors.

The number of crops is listed next to the Crops class in the Layer Manager. You can also right-click on the raster layer in the Layer Manager and select View Metadata. In the View Metadata dialog, click the Supplementary node to see the number of crops.

With the Count Crops tool, you can expect to see some false positives and some crops that were not counted. However, you can still achieve high accuracy by experimenting with different parameter settings. You can also use the Convert Crops to Shapefile tool to create a shapefile of the counted crops. Then use the ENVI vector tools to delete individual records that represent false positives.

Example: Vineyard Orthophoto

This example shows High-Resolution Orthoimagery available from the U.S. Geological Survey from April 2011, at 0.5-foot spatial resolution. The area of interest contains grape vineyards in Sonoma County, California. The green band was isolated and inverted to create a greyscale image where the crops are bright.

The average crop diameter is 1.5 meters according to the ENVI Mensuration tool. Since the crop sizes do not vary much in this field, we can keep the diameter range fairly small and use a smaller increment. Because the crops do not touch each other, we can also reduce the overlap percentage. Finally, we need to slightly lower the intensity threshold to detect the crops whose brightness levels are lower than surrounding crops. The following parameter values were used in this example:

Minimum Crop Diameter: 1.0 meters

Maximum Crop Diameter: 2.0 meters

Number of Increments: 4

Gaussian Smoothing Factor: 0.5

Include Edges: No

Allowable Crop Overlap: 30%

Intensity Threshold: 0.3

Fill Raster Crops: No

Here is the result of the Crops class overlaid on the RGB image. The final count is 848 crops:

See Also

Enhance Crops, Crop Metrics, Crop Metrics with Spectral Index, Find Rows and Remove Outliers


© 2017 Exelis Visual Information Solutions, Inc. |  Legal
My Account    |    Buy    |    Contact Us