CONTEXT

Contextual Classification


EnvironmentsPYTHON :: EASI :: MODELER
Quick linksDescription :: Parameters :: Parameter descriptions :: Details :: Example :: References

Back to top

Description


Performs frequency-based contextual classification of multispectral imagery, using a gray-level reduced image and a set of training site bitmaps.
Back to top

Parameters


context(file, dbic, dbib, valu, pwsize, dboc, dbow)

Name Type Caption Length Value range
FILE * str Input file name 1 -    
DBIC * List[int] Input raster channel 1 - 1  
DBIB * List[int] Input training site bitmaps 2 - 254 -254 -
VALU List[int] Gray-level values 0 - 254 -254 -
PWSIZE * List[int] Pixel window size 1 - 1  
DBOC * List[int] Output classified channel 1 - 1  
DBOW List[int] Raster output window 0 - 4 Xoffset, Yoffset, Xsize, Ysize

* Required parameter
Back to top

Parameter descriptions

FILE

Specifies the name of the PCIDSK image file that contains the gray-level vector-reduced image and training site bitmap segments.

DBIC

Specifies the input channel that contains the gray-level vector-reduced image. The input channel must be 8-bit data. Any 16- and 32-bit data channels should be scaled to 8-bits using the SCALE function.

DBIB

Specifies two to 254 bitmap segments that contain the training sites for each class.

Duplicate bitmap segments are not allowed. At least two bitmap segments must be specified.

VALU

Optionally specifies two to 254 values for output classes that correspond to each input training site bitmap (DBIB). Unless specified, the output classes are sequentially assigned values starting from 1 to the specified number of input bitmaps.

Up to 254 values can be handled, and up to 48 integer values may be specified.

PWSIZE

Specifies the window size to use when performing contextual classification on each pixel. The window size must be an odd integer between 3 and 21. In general, contextual classification performs better when you specify a larger window size, especially if the original input image contains complicated mixed classes (such as residential, commercial, or industrial areas). If the classes are uniform and spectrally pure, a smaller window size is sufficient.

DBOC

Specifies the output channel to receive the classification results.

DBOW

Specifies the raster window (Xoffset, Yoffset, Xsize, Ysize) over which the contextual classification is performed. If this parameter is not specified, the entire layer is processed by default.

Xoffset, Yoffset define the upper-left starting pixel coordinates of the window. Xsize is the number of pixels that define the window width. Ysize is the number of lines that define the window height.

Back to top

Details

CONTEXT performs the second of two steps in frequency-based contextual classification of multispectral imagery. It takes as input a gray-level vector-reduction image (DBIC) and a set of training site bitmap segments (DBIB), and creates a classification image (DBOC).

If an output window (DBOW) is specified, classification is performed only under the specified window.

Each input bitmap can be assigned a unique output class value (VALU) for the classification image. The contextual classifier uses a specified window size (PWSIZE) around each pixel.

The pixel window size must be an odd integer that is between 3 and 21. The default size is 3, but should be larger for images with complex class patterns, such as in urban areas. You may need to run the contextual classifier with the same input data but different settings for PWSIZE until a desired output is produced.

CONTEXT cannot classify (PWSIZE-1)/2 pixels along the edges of the image. If the output window borders the edge of the image file, the output pixels along the edge are set to zero to indicate unclassified or unknown pixels. These edge pixels are otherwise unchanged.

The error patterns caused by the contextual classification algorithm are usually located systematically along the class boundaries. This lets you understand the quality of the thematic maps produced by this algorithm.

The maximum number of pixels allowed per line for the output window is 8,192.

Back to top

Example

Perform a contextual classification by using a vector reduction image and eight training site bitmap segments in the demo file, irvine.pix. Generated classes are assigned values that are the same as those used for the maximum likelihood classifier (see the example for MLC). Set the pixel window size to 7, instead of the default 3, because some of the classes are urban. The output classification image contains zeros for (7-1)/2 = 3 pixels along the border of the image because these pixels cannot be classified.

from pci.context import context

file	=	"irvine.pix"	# input file
dbic	=	[8]	# input channel
dbib	=	list(range(9,17))	# input training bitmaps
valu	=	list(range(10,90,10))	# gray-level values
pwsize	=	[7]	# pixel window size
dboc	=	[9]	# output channel
dbow	=	[]	# process entire image

context( file, dbic, dbib, valu, pwsize, dboc, dbow )
        

The generated report is shown below.

 irvine.pix                   [S   13PIC     512P     512L] 14-Aug-90

 Segment Name     Code      Pixels   % Image

       9 Water1     10        3066      1.18
      10 Water2     20        1796       .69
      11 Urban      30       46763     18.05
      12 Range      40      119048     45.95
      13 Crop1      50       22645      8.74
      14 Crop2      60       27442     10.59
      15 Crop3      70         941       .36
      16 Forest     80       34335     13.25
Back to top

References

The CONTEXT function uses the algorithm described in the following paper:

Gong, Peng and Philip Howarth. "Frequency-Based Contextual Classification and Gray-Level Vector Reduction for Land-Use Identification", Photogrammetric Engineering & Remote Sensing, 58, no. 4 (April 1992): 423-437.

© PCI Geomatics Enterprises, Inc.®, 2026. All rights reserved.