Use this procedure to calculate statistics for images based on a classification mask.

Example


The following example performs a K-means unsupervised classification, then generates a statistics report to the screen.

; Start ENVI
e = ENVI()
 
; Open a data file
File = Filepath('qb_boulder_msi', Root_Dir = e.Root_Dir, $
   Subdir = ['data'])
Raster = e.OpenRaster(File)
 
; Return a file ID
fid = ENVIRasterToFID(Raster)
 
; Perform K-Means unsupervised classification. 
ENVI_File_Query, fid, DIMS=dims, NB=nb
ENVI_Doit,'Class_Doit', $
   FID = fid, $
   DIMS = dims, $
   POS = Lindgen(nb), $
   METHOD = 7, $
   NUM_CLASSES = 5, $
   ITERATIONS = 3, $
   CHANGE_THRESH = 0.9, $
   R_FID = ClassFID, $
   OUT_NAME = 'ClassImage'
 
; Compute statistics
ENVI_Doit, 'Class_Stats_Doit', $
   CLASS_FID = ClassFID, $
   CLASS_DIMS = dims, $
   CLASS_PTR = [0,1,2,3,4,5], $
   COMP_FLAG = 0, $
   FID = fid, $
   REPORT_FLAG = 1, $
   REP_NAME = 'class_stats.txt', $
   POS = Lindgen(nb)
   

Syntax


ENVI_DOIT, 'CLASS_STATS_DOIT', CLASS_DIMS=array, CLASS_FID=file ID, CLASS_PTR=array, COMP_FLAG={0 | 1 | 2} [, COV=variable] [, DMAX=variable] [, DMIN=variable] [, EVAL=variable] [, EVEC=variable], FID=file ID [, HIST=variable] [, MEAN=variable], POS=array [, REP_NAME=array] [, REPORT_FLAG={0 | 1 | 2}] [, STA_NAME=string array] [, STDV=variable] [, /TO_SCREEN]

Keywords


CLASS_DIMS

Use this keyword to specify the spatial dimensions on which to perform the operation. CLASS_DIMS is a five-element array of long integers with the following definitions:

  • CLASS_DIMS[0]: Unused for this function, set to -1
  • CLASS_DIMS[1]: The starting x pixel (0)
  • CLASS_DIMS[2]: The ending x pixel
  • CLASS_DIMS[3]: The starting y pixel (0)
  • CLASS_DIMS[4]: The ending y pixel

Note that the dimensions specified must be within the classification image, including the first pixel offsets.

CLASS_FID

Use this keyword to specify the file ID of the classification image.

CLASS_PTR

Use this keyword to specify an array of long integers representing class numbers on which to perform statistics.

COMP_FLAG

Set this keyword equal to a bit value indicating the calculations to perform.

  • Bit 0: Not used
  • Bit 1: Enables the calculation of histograms
  • Bit 2: Enables the calculation of covariance
  • Bits 3 to 15: Not used

COV (optional)

Use this keyword to specify a named variable that contains the returned covariance matrix. You must set bit 2 in COMP_FLAG (i.e., COMP_FLAG=4) to generate the covariance matrix.

DMAX (optional)

Use this keyword to specify a named variable that contains the array of data maximums, one for each band position.

DMIN (optional)

Use this keyword to specify a named variable that contains the array of data minimums, one for each band position.

EVAL (optional)

Use this keyword to specify a named variable that contains the eigenvalues. You must set bit 2 in COMP_FLAG (i.e., COMP_FLAG=4) to generate the covariance matrix.

EVEC (optional)

Use this keyword to specify a named variable that contains the eigenvector. You must set bit 2 in COMP_FLAG (i.e., COMP_FLAG=4) to generate the covariance matrix.

FID

The file ID (FID) is a long-integer scalar with a value greater than 0. An invalid FID has a value of -1. The FID is provided as a named variable by any routine used to open or select a file. Often, the FID is returned from the keyword R_FID in the ENVIRasterToFID routine. Files are processed by referring to their FIDs. If you work directly with the file in IDL, the FID is not equivalent to a logical unit number (LUN).

HIST (optional)

Use this keyword to specify a named variable that contains the histogram array. You must set bit 1 in COMP_FLAG (i.e., COMP_FLAG=2) to generate the histogram output.

MEAN (optional)

Use this keyword to specify a named variable that contains the array of data means, one for each band position.

POS

Use this keyword to specify an array of band positions, indicating the band numbers on which to perform the operation. This keyword indicates the spectral subset of bands to use in processing. POS is an array of long integers, ranging from 0 to the number of bands minus 1. Specify bands starting with zero (Band 1=0, Band 2=1, etc.) For example, to process only Bands 3 and 4 of a multi-band file, POS=[2, 3].

POS is typically used with individual files. The example code below illustrates the use of POS for a single file with four bands of data:

pos=[0,1,2,3]
envi_doit, 'envi_stats_doit', dims=dims, fid=fid, pos=pos, $
  comp_flag=3, dmin=dmin, dmax=dmax, mean=mean, stdv=stdv, hist=hist

But what if you need to create an output file consisting of data from different bands, each from different files? Library routines such as CF_DOIT and ENVI_LAYER_STACKING_DOIT can accomplish this, but they use the POS keyword differently. Suppose you have four files, test1, test2, test3, and test4, with corresponding FIDs of fid1, fid2, fid3, and fid4, respectively. In the following example, you want Band 3 from test1 in the first position, Band 2 from test2 in the second position, Band 6 from test3 in the third position, and Band 4 from test4 in the fourth position. The code should be as follows:

fid_array = [fid1,fid2,fid3,fid4]
pos=[2,1,5,3]
envi_doit, 'cf_doit', dims=dims, fid=fid_array
out_name='test_composite_file'

REP_NAME (optional)

Use this keyword to specify a string array containing the filename for the output report file.

REPORT_FLAG (optional)

Set this keyword equal to a bit value indicating the type of output reports desired. Logically AND the bit values together to get the desired reports.

  • Bit 0: Basic statistics (REPORT_FLAG=1)
  • Bit 1: Generate histogram report (default, REPORT_FLAG=2)
  • Bit 2: Generate covariance report (REPORT_FLAG=4)
  • Bits 3 to 15: Not used

If REPORT_FLAG=0, no output report is generated.

STA_NAME (optional)

Use this keyword to specify a string array containing the filename for the output statistics file.

STDV (optional)

Use this keyword to specify a named variable that contains the array of data standard deviations, one for each band position.

TO_SCREEN (optional)

Set this keyword to print the report on the screen. This keyword only controls the display of the secondary statistics report window. The main statistics report window will appear regardless of this keyword.

API Version


4.3