Combining IDL with ENVI Band Math gives you more flexibility in creating powerful mathematical operations. You can take advantage of IDL's features, write user functions, and write custom routines to perform Band Math operations. In most cases, you can apply algorithms directly in the Band Math dialog without having to write a user function; however, if you choose to write one, this topic provides some guidelines.

Band Math user functions are simple to write and to execute as expressions. The only requirements are that they accept one or more image arrays as input and that they output a single-band, 2D array with the same dimensions as the input bands.

User functions have the following structure. They accept the input bands, process the data, and return the result.

FUNCTION function_name, b1, [b2,..., bn, parameters and keywords]
  processing steps            
  RETURN, result
END

For example:

FUNCTION BandMathRatio, b1, b2
  result = float(b1/b2)
  RETURN, result
END

To run this user function, type the following in the Enter an expression field of the Band Math dialog:

BandMathRatio(b1, b2)

The processing steps have the same constraints as Band Math expressions. Input data are tiled; therefore, functions like MIN and MAX are invalid since they return only the minimum or maximum of the current tile, not those of the input band. If the input bands are large, you should avoid processing that requires the entire band in memory at once.

After writing a user function, save it as a .pro or .sav file and place it in the custom_code directory of your ENVI installation path. ENVI will automatically compile and restore the user function when it restarts.