6
How to create and customize a User Interface (UI) in ENVI Tasks?
It is possible to create a dynamic User interface when customizing an ENVI Task, as proposed in the below example.
More details in the link below
https://www.nv5geospatialsoftware.com/docs/CustomTasksTutorial.html#Create
Creating a User Interface (UI) in a customed ENVI task will require creating a Style Sheet first
Examples of various Style Sheet files (.style extensions) for ENVI tasks are available in the following folder:
C:\Program Files\NV5\ENVI62\resource\templates\tasks
Below is an example of a customized ENVI task called classthresholds including a customized UI to select
- The input raster
- The classifier method using radio buttons
- The threshold value
For input, the task will require :
- A raster image
- A threshold value
- A method to apply the threshold
Depending on the chosen method, the classifier will behave differently
- MAX threshold: all pixel values above the threshold will be set to the maximum of the input raster
- MIN Threshold: all pixel values below or equal to the threshold will be set to the minimum of the input raster
- The Classthresholds.style file describes the content of the UI. In this example it includes
- 2 radio buttons to select the method to apply the threshold: MAX Threshold or MIN Threshold
- A text field to input the threshold value.
In addition, a field to select the input raster, is directly created when running the runclassthresholds_ui .pro with the command
raster = UI.SelectInputData(/RASTER)
It should be saved in the /NV5/ENVIx.x/custom_code/ folder.
{
"schema": "envitask_3.0",
"parameters": [
{
"name": "CLASSIFIER",
"type": "IDLRadioButtons_UI",
"keywords": {
"OPTIONS": ["MAX Threshold", "MIN Threshold"]
},
},
{
"name": "THRESHOLDS",
"type": "IDLNumeric_UI",
"keywords": {
"TYPE": "double",
},
}
]
}
- The Classthresholds.task file includes the task template of the customized task, that will use the above UI.
The task template maps keywords of the IDL processing program - Classthresholds.pro - to the task parameters.
It should be saved in the /NV5/ENVIx.x/custom_code/ folder.
{
"name": "classthresholds",
"base_class": "ENVITaskFromProcedure",
"routine": "classthresholds",
"display_name": "Compute Class Thresholds",
"description": "Computes class thresholds from input raster.",
"schema": "envitask_3.3",
"revision": "1.0.0",
"parameters": [
{
"name": "RASTER_URI",
"display_name": "Select a classification image",
"type": "ENVIURI",
"direction": "input",
"required": true,
"description": "This is the input classification image"
},
{
"name": "CLASSIFIER",
"display_name": "Classifier",
"type": "string",
"direction": "input",
"default": "MAX Threshold",
"required": true,
"description": "Select the threshol method"
},
{
"name": "THRESHOLDS",
"display_name": "Select a threshold value",
"type": "double",
"direction": "input",
"required": true,
"description": "Input threshold value"
},
{
"name": "OUTPUT_RASTER_URI",
"display_name": "Output Raster URI",
"type": "ENVIURI",
"direction": "output",
"required": false,
"description": "Output thresholded raster",
"auto_extension": ".dat"
}
]
}
- The Classthresholds.pro file is the IDL program that will contain the processing steps to be executed in ENVI +IDL.
It would need to be compiled and saved as a .sav file to be run with ENVI only (without IDL).
It should be saved in the /NV5/ENVIx.x/custom_code/ folder.
; CUSTOM TASK CODE
PRO classthresholds, $
RASTER_URI = raster_uri, $
CLASSIFIER = classifer, $
THRESHOLDS = thresholds, $
OUTPUT_RASTER_URI = output_raster_uri
COMPILE_OPT IDL2, hidden
ON_ERROR, 2
; Access the current ENVI session
e = ENVI(/CURRENT)
; Get the User Interface object
UI = e.UI
; Open raster
raster= e.Openraster(raster_uri)
; Get the number of bands, the metadata object and the data
nbands = raster.nbands
metadata = raster.METADATA
b1 = raster.GetData()
; apply threshold method
IF classifer EQ 'MAX Threshold' Then b1[WHERE(b1 GT thresholds)]=MAX(b1)
IF classifer EQ 'MIN Threshold' Then b1[WHERE(b1 LE thresholds)]=MIN(b1)
; Get output raster URI and save the output raster
if output_raster_uri eq !NULL || output_raster_uri eq '' then begin
output_raster_uri = e.GetTemporaryFilename('.dat')
endif
outputRaster = ENVIRaster(b1, inherits_from=raster, uri=output_raster_uri)
outputRaster.save
result = DIALOG_MESSAGE('end', /INFORMATION, TITLE='Class Thresholds')
END
- Last step consists in building a runclassthresholds_ui .pro IDL code to deploy the custom task in ENVI+IDL.
Again, this one should be compiled and saved as a .sav file for usage in ENVI only (without IDL)
This file should be saved in /NV5/ENVI6.2/extensions folder.
It will create a new menu in ENVI Toolbox: /Extensions/runclassthresholds_ui to execute the custom task
PRO runclassthresholds_ui_extensions_init
COMPILE_OPT IDL2, HIDDEN
; Get the current ENVI session
e = ENVI(/CURRENT)
; Add the custom task as an extension to the ENVI toolbox
e.AddExtension, 'Compute Class Thresholds', $
'runclassthresholds_ui ';, PATH='/Classification'
END
PRO runclassthresholds_ui
COMPILE_OPT IDL2, hidden
ON_ERROR, 2
; Get the current ENVI session
e = ENVI(/CURRENT)
; Run the custom task
Task = ENVITask('classthresholds')
dynamicUI = e.UI.SelectTaskParameters(Task)
IF (dynamicUI NE 'OK') THEN RETURN
Task.Execute
; Re-open the input and output raster dataset
raster=e.OpenRaster(task.raster_URI)
outputRaster = e.OpenRaster(task.OUTPUT_RASTER_URI)
; Add the result to the Data Manager
DataColl = e.Data
DataColl.Add, raster
DataColl.Add, outputraster
; Display in ENVI view
view = e.GetView()
layer = view.CreateLayer(Raster)
layer = view.CreateLayer(outputRaster)
print, 'Thresholded raster displayed in ENVI view'
END
- Start the new /Extensions/runclassthresholds_ui menu in the ENVI Toolbox to execute the custom task.

---------------------------------------
created by BC (EU) on 6/2/2026
reviewed by MM on 6/2/2026