Build a New Decision Tree

Input data can be from various sources and data types. For example, you can use multispectral data in conjunction with digital elevation data to find pixels with low vegetation and high slopes. You can use georeferenced files that are in different projections with different pixel sizes in a single decision tree and ENVI reprojects and resample them on-the-fly. ENVI can calculate special variables, such as NDVI, on-the-fly and use them in the expressions.

Follow these steps to build a new decision tree:

  1. From the Toolbox, select Classification > Decision Tree > New Decision Tree. The ENVI Decision Tree dialog appears with a single decision node and two classes (leaves).
  2. Click Node 1. The Edit Decision Properties dialog appears.
  3. Enter a node Name and an Expression (see Decision Tree Variables and Expressions), then click OK. The Variable/File Pairings dialog appears.
  4. In the Variable/File Pairings dialog, select the variable name. The Select File to Associate with Variable dialog appears.
  5. Select the input file or band to associate to the variable.
  6. In the ENVI Decision Tree dialog, add a new node by right-clicking on a Class button and selecting Add Children. ENVI adds two children below the node and clears the title from the node button.
  7. Click the new, blank node button. The Edit Decision Properties dialog appears.
  8. Enter node Name and an Expression, then click OK.
  9. In the Variable/File Pairings dialog, click on the variable name. The Select File to Associate with Variable dialog appears.
  10. Select the input file or band to associate to the variable.
  11. Repeat steps 6 through 10, adding as many nodes as necessary.
  12. When the tree is finished, select Options > Execute from the ENVI Decision Tree menu bar.

Decision Tree Variables and Expressions

The expressions used in ENVI’s decision tree classifier are similar to those used in Band Math. They must produce single band output and have a binary result of 0 or 1. The 0 result is sent to the “No” branch and the 1 result is sent to the “Yes” branch of the decision tree.

The expressions can include math functions, relational operators, boolean operators, and other IDL functions as shown in the following table.

Category

Available Functions

Basic arithmetic

Addition (+), subtraction (-), multiplication (*), and division (/)

Trigonometric functions

sin(x), cos(x), and tan(x)

Arcs: asin(x), acos(x), and atan(x)

Hyperbolics: sinh(x), cosh(x), and tanh(x)

Relational and logical operators

LT, LE, EQ, NE, GE, GT

AND, OR, NOT, XOR

maximum (>) and minimum (<)

Other math functions

exponent (^) and natural exponent

Natural logarithm: alog(x)

Log base 10: alog10(x)

Integer rounding: round(x), ceil(x)

Square root: sqrt(x)

Absolute value: abs(x)

The variables in ENVI’s decision tree classifier refer to a band of data or to a special function that acts on the data. The variable names must be within curly brackets, such as {variable name}, or be named bx, where x is a number. If a variable is assigned to a multiband file, the variable must have a subscript, in square brackets, referring to a band number (band numbers are 1 to the number of bands). For example, {pc[2]} refers to band 2 of the file assigned to the variable pc.

ENVI’s special variable names do calculations on-the-fly, and use the results in the expression. These special variable names must be within curly brackets. The following are acceptable special variables:

You can use any number of different expressions within the decision tree classifier as long as the expression results in a single, binary decision (true or false answer for each pixel). The following examples show how to define various simple and complex decisions:

Note: The local statistics variables can only be used on georeferenced files that have the same projection as the selected base file, otherwise statistics are calculated using the entire band.

Use IDL Functions in Node Expressions

The Expression field also accepts user-defined functions written in IDL. Derive and apply these functions as expressions in the same manner as user-defined functions in the Band Math and Spectral Math tools. However, the result of the overall expression must still equal 0 or 1.

Because ENVI + IDL provides access to IDL’s capabilities, you can use the power of built-in IDL features, IDL user functions, or write your own decision tree expressions to perform custom operations. These functions are required to accept one or more pixel variables as input. Moreover, the overall expression must equal 0, 1, or a binary array (of the same spatial size as the input data) in which each pixel value is 0 or 1. Save the functions in a directory that is within the IDL path list (for example, the save_add directory in the ENVI distribution) so that ENVI auto-compiles them.

Example Custom Decision Tree Functions

This example function returns a mask (byte array) where the specified values in the input data are set to 1 and all other pixels are set to 0:

FUNCTION dt_choose_values, data, values
 
info = SIZE(data)
result = MAKE_ARRAY(/BYTE, SIZE = info)
FOR index = 0L, (N_ELEMENTS(values) - 1) DO $
   result += (data EQ values[index])
 
RETURN, result
END

To call this function from the Expression field to derive a mask for values of 20, 22, 24, and 26 in the first band (b1) in the bhtmref.img file in the data directory of the ENVI distribution, use the following syntax:

dt_choose_values(b1, [20, 22, 24, 26])