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 requires a separate license for the ENVI Crop Science Module; contact your sales representative for more information.

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 Find Hotspots 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:

f

Data should be in units of reflectance before creating spectral indices. See Spectral Indices 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 offers a variety of parameters, which will need to 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. The Count and Rasterize dialog appears.
  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. Tip: 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. The Count Crops tool finds crops up to half of the specified increment outside of the minimum and maximum diameters.
  8. 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.
  9. 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:
  10. 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.

  11. Optional: Enter a percentage for Allowable Crop Overlap. This is the percentage of allowable overlap between two adjacent crops before one of them is considered a duplicate and removed. Overlap is measured by how much the diameter of a smaller circle is overlapped by a larger circle. The default value is 50%.

    When the overlap is greater than the allowable overlap, the crop with the lower confidence is removed. The confidence is a measure of how much the crop resembles a circle.

    For a group of crops that overlap, ENVI checks them in the order of highest to lowest confidence. Suppose that in the following example, crop A has the highest confidence, crop B is second, and crop C has the least confidence. With less than 50% of allowable overlap, crops A and C would remain. Crop B would be removed as a duplicate of A and not checked against C.

    A general tip is to enter a smaller value for Allowable Crop Overlap if the crops are distinctly separated from one another.

  12. 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.
  13. 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.
  14. Enable the Fill Raster Crops option to display filled circles instead of outlines in the classification result. The default value is No.
  15. Select an output filename and location for the Output Crops Raster. This is a classification raster showing circles that represent individual crops.
  16. 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 view and uses the resolution level at which you are viewing the image. See Preview for details on the results. To preview a different area in your image, pan and zoom to the area of interest and re-enable the Preview option.

  17. Enable the Display result check box to display the output in the view when processing is complete. Otherwise, if the check box is disabled, the result can be loaded from the Data Manager.

  18. To see a model-based version of this tool that shows how the tool is constructed from individual tasks, click Open in Modeler.

  19. To reuse these task settings in future ENVI sessions, save them to a file. Click the down arrow and select Save Parameter Values, then specify the location and filename to save to. Note that some parameter types, such as rasters, vectors, and ROIs, will not be saved with the file. To apply the saved task settings, click the down arrow and select Restore Parameter Values, then select the file where you previously stored your settings.

  20. To run the process in the background, click the down arrow and select Run Task in the Background. If an ENVI Server has been set up on the network, the Run Task on remote ENVI Server name is also available. The ENVI Server Job Console will show the progress of the job and will provide a link to display the result when processing is complete. See ENVI Servers for more information.

  21. Click OK.

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 extracted from the original RGB image, then enhanced to create a grayscale 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