SIEVE

Sieve filter (class merging)


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

Back to top

Description


Reads an image channel and merges image value polygons smaller than a user-specified threshold with the largest neighboring polygon. This function is typically used to filter small classification polygons from a classification result.
Back to top

Parameters


sieve(file, dbic, dboc, sthresh, keepvalu, connect)

Name Type Caption Length Value range
FILE * str Input file name 1 -    
DBIC * List[int] Input raster channel 1 - 1  
DBOC * List[int] Output raster channel 1 - 1  
STHRESH List[int] Polygon size threshold 0 - 1 1 -
KEEPVALU List[int] Values excluded from filtering 0 - 48  
CONNECT List[int] Connectedness of lines 0 - 1 4 | 8
Default: 4

* Required parameter
Back to top

Parameter descriptions

FILE

Specifies the name of the GDB-supported file that contains the input and output image channels to process.

DBIC

Specifies the image channel that contains the classification polygons.

DBOC

Specifies the image channel to receive the merged classification result. The output channel may be the same as the specified input channel.

Note: 32-bit real data will be truncated to integer values.

STHRESH

Specifies the size, in pixels, of the smallest polygon not to be merged into a neighbor. This value must be greater than zero.

Note: Large Polygon Size Threshold values require more memory.

KEEPVALU

Specifies a list of up to 48 image values to exclude from the sieve operation. Polygons with these values will not be replaced, nor will other polygons be replaced with these values unless the polygon is surrounded by pixels in this list.

CONNECT

Specifies whether polygons are determined on the basis of eight connectedness, or four connectedness.

Supported values are:

Polygons are determined on the basis of adjacent pixels of the same value. In a four-connected polygon, pixels are considered adjacent if they are in contact horizontally or vertically. Eight connectedness also includes pixels in contact on the diagonal.

Back to top

Details

SIEVE performs a sieve filtering operation on the input data. The sieve filter removes all polygons smaller than the given size, measured in pixel area. Each polygon smaller than the defined threshold is merged with its largest neighbor.

A polygon is defined as a four- or eight-connected collection of pixels with the same digital value. Eight-connected implies that two pixels with the same gray-level value are part of the polygon if they are side-by-side, one above the other, or diagonally in contact. Four-connected, on the other hand, only includes side-by-side, or one above the other contact.

SIEVE may need to make multiple passes to remove all polygons smaller than the threshold size, though this is rarely necessary. Note that SIEVE operates on integer values, and 32R input channels will lose precision.

SIEVE builds up a list of all the polygons in the input channel in memory; therefore, input channels with many small polygons require much more memory than those with relatively few polygons. An error occurs if SIEVE exhausts available memory for storing polygon information. It may be helpful to run FMO to reduce the number of polygons before running SIEVE.

SIEVE copies the metadata from the input channel to the output channel.

Back to top

Example

Pass the supervised classification result in channel 7 of irvine.pix through a sieve filter with a threshold of 6, to remove any polygons of 5 pixels or less.

from pci.sieve import sieve

file	=	"irvine.pix"
dbic	=	[7]
dboc	=	[8]
sthresh	=	[6]	# polygon size threshold
keepvalu	=	[]	# no keep value
connect	=	[]	# default, 4-connection

sieve( file, dbic, dboc, sthresh, keepvalu, connect )

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