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:

  • {slope}: The slope calculated from a DEM file.
  • {aspect}: The aspect calculated from a DEM file.
  • {ndvi}: NDVI calculated from file. If the sensor type is set in the header, the bands used to calculate the NDVI are automatically found. If ENVI does not know which bands to use, it will prompt you to enter the band numbers.
  • {tascap[n]}: Tasseled Cap transform. The subscript, n, points to which tasseled cap result to use in the expression; for example, for TM data, {tascap[2]} will use the greenness band.
  • {pc[n]}: Principal components. The subscript, n, points to which PC band to use in the expression.
  • {mnf[n]}: Minimum noise fraction. The subscript, n, points to which MNF band to use in the expression.
  • {lpc[n]}: Local principal components. Uses only the surviving pixels in the calculations.
  • {lmnf[n]}: Local minimum noise fraction. Uses only the surviving pixels in the calculations.
  • {mean[n]}: The mean for band n.
  • {stdev[n]}: The standard deviation for band n.
  • {min[n]}: The minimum of band n.
  • {max[n]}: The maximum of band n.
  • {lmean[n]}: Local mean. The mean of only the surviving pixels.
  • {lstdev[n]}: Local standard deviation. The standard deviation of only the surviving pixels.
  • {lmin[n]}: Local minimum. The minimum of only the surviving pixels.
  • {lmax[n]}: Local maximum. The maximum of only the surviving pixels.

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:

  • Pixels with values greater than 20 in band 1, and values less than or equal to 45 in band 2 are identified by the following expression:

    (b1 GT 20) AND (b2 LE 45)
  • Pixels with NDVI (Normalized Difference Vegetation Index) values greater than or equal to 0.3 are identified by the following expression:

    {ndvi} GE 0.3
  • Pixels with values in band 1 greater than the mean of band 2 plus twice the standard deviation of band 2 are identified by the following expression:

    b1 GT ({mean[2]} + 2*{stdev[2]})
  • Pixels with a slope greater than 15 degrees and a northern aspect are identified by the following expression:

    ({slope} GT 15) AND (({aspect} LT 90) or ({aspect} GT 270))

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])