Use this procedure to calculate ratios of selected image bands.

Example


This example calculates a simple ratio (near-infrared / red) for a QuickBird multispectral image.

; Start ENVI
e = ENVI()
 
; Open a data file
File = Filepath('qb_boulder_msi', Root_Dir = e.Root_Dir, $
   Subdir = ['data'])
Raster = e.OpenRaster(File)
 
; Determine an output file
OutFile = e.GetTemporaryFilename()
 
; Return a file ID
fid = ENVIRasterToFID(Raster)
 
; Calculate simple ratio index
; QuickBird band 4 is near-infrared
; Band 3 is red
ENVI_File_Query, fid, DIMS=dims
ENVI_Doit, 'Ratio_Doit', $
   FID = [fid, fid], $
   DIMS = dims, $
   POS = [3,2], $
   OUT_NAME = OutFile
 

Syntax


ENVI_DOIT, 'RATIO_DOIT', /CHECK, DIMS=array, FID=array of file IDs, /IN_MEMORY, O_MAX=value, O_MIN=value, OUT_BNAME=string array, OUT_DT={1 | 4}, OUT_NAME=string, POS=array, R_FID=variable

Keywords


CHECK

Set this keyword to check for divide-by-zero errors. Any such errors are set to 0.

DIMS

The “dimensions” keyword is a five-element array of long integers that defines the spatial subset (of a file or array) to use for processing. Nearly every time you specify the keyword FID, you must also specify the spatial subset of the corresponding file (even if the entire file, with no spatial subsetting, is to be processed).

  • DIMS[0]: A pointer to an open ROI; use only in cases where ROIs define the spatial subset. Otherwise, set to -1L.
  • DIMS[1]: The starting sample number. The first x pixel is 0.
  • DIMS[2]: The ending sample number
  • DIMS[3]: The starting line number. The first y pixel is 0.
  • DIMS[4]: The ending line number

To process an entire file (with no spatial subsetting), define DIMS as shown in the following code example. This example assumes you have already opened a file using ENVI_SELECT or ENVI_PICKFILE:

  envi_file_query, fid, dims=dims

FID

Use this keyword to specify a long-integer vector representing file IDs for the ratio pairs. Each pair is sequential in the list, i.e., (0,1) (2,3) (4,5) etc.

IN_MEMORY

Set this keyword to specify that output should be stored in memory. If you do not set IN_MEMORY, output will be stored on disk and you must specify OUT_NAME (see below).

O_MAX

Use this keyword to specify the output data maximum. This keyword is only used when OUT_DT is set to byte.

O_MIN

Use this keyword to specify the output data minimum. This keyword is only used when OUT_DT is set to byte.

OUT_BNAME

Use this keyword to specify a string array of output band names.

OUT_DT

This keyword indicates the IDL data type of the output data. Set the keyword to one of the following integer values:

  • 1: Byte (8 bits)
  • 4: Floating-point (32 bits)

OUT_NAME

Use this keyword to specify a string with the output filename for the resulting data. If you set the keyword IN_MEMORY, you do not need to specify OUT_NAME.

POS

Specify an integer array of the form [numerator, denominator], indicating which bands to process. Band numbers are zero-based. For example, to compute a band ratio of Band 3 / Band 4, set POS = [2,3].

R_FID

ENVI Classic library routines that result in new images also have an R_FID, or “returned FID.” This is simply a named variable containing the file ID to access the processed data. Specifying this keyword saves you the step of opening the new file from disk.

API Version


4.2