This task finds rows within an ENVIAgCrops object, removes crops that are outside the rows, and creates a classification raster with the remaining crop locations and sizes. It optionally creates polyline and polygon regions of interest (ROIs) centered over each row. You must run ENVIAgCropCount, AgCropCount Task, or AgCountAndRasterizeCrops Task first before running this task.
This task requires a separate license for the ENVI Crop Science Module; contact your sales representative for more information.
This example performs the following steps:
- Opens an RGB image of emerging cotton plants, captured by an unmanned aerial vehicle (UAV). Image courtesy of Drone Global Network.
- Runs AgCropCount Task on the green band of the image, to count the crops and to create an ENVIAgCrops object.
- Finds rows within the crops object, removes crops that are outside the rows, and creates a classification raster with the remaining crop locations and sizes.
- Displays the input image, the crops raster (with outliers removed), and the row polyline ROI.
e = ENVI()
File = Filepath('Cotton.dat', $
Raster = e.OpenRaster(File)
subset = ENVISubsetRaster(Raster, BANDS=)
countTask = ENVITask('AgCropCount')
countTask.INPUT_RASTER = subset
countTask.MINIMUM_CROP_DIAMETER = 9
countTask.MAXIMUM_CROP_DIAMETER = 12
countTask.GAUSSIAN_FACTOR = 0.8
countTask.PERCENT_OVERLAP = 60
countTask.INTENSITY_THRESHOLD = 0.81
Task = ENVITask('AgFindRowsAndRemoveOutliers')
Task.INPUT_CROPS = countTask.OUTPUT_CROPS
Task.DISTANCE_THRESHOLD = 14.5
Task.INLIER_FRACTION = 0.7
Task.MINIMUM_CROPS_PER_ROW = 25
Task.MAXIMUM_SLOPE = 2.0
Task.FILLED = 'true'
View = e.GetView()
Layer1 = View.CreateLayer(subset)
Layer2 = View.CreateLayer(Task.OUTPUT_RASTER)
roiLayer = Layer2.AddROI(Task.OUTPUT_ROW_ROIS)
Print, 'Number of outliers removed: ', Task.OUTPUT_NREMOVED
Print, 'Number of rows found: ', Task.OUTPUT_NROWS
Result = ENVITask('AgFindRowsAndRemoveOutliers')
Input properties (Set, Get): DISTANCE_THRESHOLD, FILLED, INLIER_FRACTION, INPUT_CROPS, MAXIMUM_SLOPE, MINIMUM_CROPS_PER_ROW, OUTPUT_CROPS_URI, OUTPUT_RASTER_URI, OUTPUT_REMOVED_CROPS_URI, OUTPUT_ROWS_ROIS_URI, ROW_ANGLE, ROW_SPACING
Output properties (Get only): OUTPUT_CROPS, OUTPUT_NCROPS, OUTPUT_NREMOVED, OUTPUT_NROWS, OUTPUT_RASTER, OUTPUT_REMOVED_CROPS, OUTPUT_ROW_ROIS
Properties marked as "Set" are those that you can set to specific values. You can also retrieve their current values any time. Properties marked as "Get" are those whose values you can retrieve but not set.
This task inherits the following methods from ENVITask:
This task inherits the following properties from ENVITask:
This task also contains the following properties:
Specify a distance threshold value in meters. The task calculates the distance from each crop center to the row line. It removes crops from that row if the distance is greater than the DISTANCE_THRESHOLD value that you provide. If you do not specify a value, the distance threshold is one-third of the row spacing, by default. If the input crops object does not have a spatial reference, enter the distance in pixels.
Set this property to true to create filled circles in the output crops classification raster. The default is false.
Specify a value ranging from 0 to 1.0. This is the fraction of candidate crops that each row should consist of, to be considered a valid row. The default value is 0.5 (50%). If the crops object has too many outliers, the tool will not correctly filter them out. In this case, set INLIER_FRACTION to a higher fraction to remove more outliers. If the rows vary greatly in the number of crops they contain, then set this parameter to a smaller fraction. Increase this value if there are many outliers and they are being identified as false rows. If the rows vary greatly from the rows surrounding them (not gradually across the field), then set this parameter to a smaller fraction. This parameter can be used in conjunction with MINIMUM_CROPS_PER_ROW, which sets an absolute minimum for all rows. For instance, say a field gradually varies from 50 crops per row on the left to 20 crops per row on the right. With the default fraction of 0.5, rows on the left must have at least 25 crops and rows on the right must have at least 10. If there are many outliers and there are false rows with more than 25 crops on the left and 10 on the right, the inlier fraction can be increased to exclude them. On the other hand, if there was a single valid row of 20 crops on the left (next to the rows of 50), an inlier fraction of 0.5 would exclude it and the fraction would have to be lowered.
Specify an input ENVIAgCrops object.
Specify the maximum amount (in degrees) that the slope of a row line can differ from the primary direction that the algoritihm initially determined. For example, if the field direction is 45 degrees and you specify a value of 1, then the row lines can have a slope of 44 to 46 degrees to be valid. The default value is 2 degrees.
Specify the number of crops required to be considered a row. The minimum number is 2, and the default is 3.
This is a reference to the output crop data, after outliers have been removed.
Specify a string with the fully qualified path and filename for OUTPUT_CROPS. If you do not specify this property, the output crop file is only temporary. Once the crop file has no remaining references, ENVI deletes the temporary file.
This is the output number of crops, after outliers have been removed.
This is the number of crops removed because they did not belong in a row.
This is the number of crop rows found.
This is a reference to the output crops classification raster.
Specify a string with the fully qualified filename and path of the associated OUTPUT_RASTER. If you do not specify this property, or set it to an exclamation symbol (!), a temporary file will be created.
This is a reference to the output ENVIAgCrops object containing the removed crops.
Specify a string with the fully qualified filename and path for the output JSON file that will contain the removed crops.
This is a reference to an output array of ROIs identifying the crop rows.
Specify a string with the fully qualified filename and path for the output XML file containing the crop row ROIs.
The row angle is calculated automatically. To override it, specify the primary angle of the rows in degrees clockwise from 0, where a value of 0 represents a horizontal alignment of the field.
The spacing between the rows is calculated automatically. To override it, specify the row spacing in meters. If the input ENVIAgCrops object does not have a spatial reference, specify the spacing in pixels.
Crop Science 1.0.1
Crop Science 1.1.1
Added ROW_ANGLE and ROW_SPACING properties
AgCropCount Task, AgFindAndRasterizeCropGaps Task