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

Harris Geospatial / Docs Center / ENVI API / Crop Science / ENVIAgCropCount



This function locates and counts crops in high-resolution, single-band images.

This object is part of ENVI Crop Science, which requires a separate license and installation.


This example performs the following steps.

  1. Opens an orthophoto of a citrus orchard.
  2. Creates a spectral index raster to make the citrus trees bright against the background. A Modified Triangular Vegetation Index (MTVI) works well in this case.
  3. Tip: See the ENVISpectralIndexRaster topic in ENVI Help for a full list of spectral indices. Or, run ENVIQuerySpectralIndicesTask first to see what indices are available for your particular image.

  4. Runs ENVIAgCropCount to count the trees and to create an ENVIAgCrops object.
  5. Prints the ENVIAgCrops object properties.
; Start the application
; Open an input file
File = Filepath('CitrusOrthophoto.dat', $
  Subdir=['data','crop_science'], $
Raster = e.OpenRaster(File)
; Preprocess the image so that crops are bright
MTVIImage = ENVISpectralIndexRaster(Raster, 'MTVI')
; Count the crops and output an ENVIAgCrops object
outCrops = ENVIAgCropCount(MTVIImage, 2.0, 5.0, $
  OUTPUT_NCROPS = outputNCrops, $
; Print the crop count
Print, outputNCrops




Result = ENVIAgCropCount(Input_Raster, Minimum_Crop_Diameter, Maximum_Crop_Diameter [, Keywords=value])

Return Value

This function returns a reference to an ENVIAgCrops object.



Specify a single-band ENVIRaster object.


Specify the minimum crop diameter. The diameter is measured in meters if the input raster has a spatial reference. Otherwise, specify the number of pixels for the diameter.

ENVIAgCropCount 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 up the area into separate images to process, each with a similar range of crop diameters.


Specify the maximum crop diameter. The diameter is measured in meters if the input raster has a spatial reference. Otherwise, specify the number of pixels for the diameter.






ERROR (optional)

Set this keyword to a named variable that will contain any error message issued during execution of this routine. If no error occurs, the ERROR variable will be set to a null string (''). If an error occurs and the routine is a function, then the function result will be undefined.

When this keyword is not set and an error occurs, ENVI returns to the caller and execution halts. In this case, the error message is contained within !ERROR_STATE and can be caught using IDL's CATCH routine. See IDL Help for more information on !ERROR_STATE and CATCH.

See the Manage Errors topic in ENVI Help for more information on error handling.


Specify a Gaussian smoothing factor to use before searching for crops. This is the fraction of the maximum search diameter at which smoothing should occur. The default value is 0.5. To disable Gaussian smoothing, set GAUSSIAN_FACTOR to 0.

INCLUDE_EDGES (optional)

Set this property to include crops that are touching or are very close to image and mask edges.


Specify the fraction of the maximum crop intensity, below which crop detections will be removed.


Specify the number of increments to use when searching crops. Use this property in conjunction with MAXIMUM_CROP_DIAMETER and MINIMUM_CROP_DIAMETER. The number of increments 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 exactly 1, 2, 3, 4, and 5 meters.


Specify a string with a fully qualified filename and path, to save an ENVIAgCrops object to a JSON-formatted text file.

OUTPUT_NCROPS (optional)

Specify a variable name that will contain the number of crops that were counted.


Specify the percentage of allowable overlap between crops before one of them is removed from consideration. The default value is 50.0. To disable the overlapping percentage, set PERCENT_OVERLAP to 100. To allow no overlapping at all, set PERCENT_OVERLAP to 0. Enter smaller values if the crops are distinctly separated from one another.

Version History




Added OUTPUT_NCROPS keyword

See Also

ENVIAgCropCountTask, ENVIAgCrops

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