| Environments | PYTHON :: EASI :: MODELER |
| Quick links | Description :: Parameters :: Parameter descriptions :: Details :: Examples :: Algorithm :: Related |
| Back to top |
| Back to top |
errdiff(file, dbic, dboc, dbpct)
| Name | Type | Caption | Length | Value range |
|---|---|---|---|---|
| FILE * | str | Input file name | 1 - | |
| DBIC * | List[int] | Input channels or layers | 3 - 3 | |
| DBOC * | List[int] | Output channel or layer | 1 - 1 | |
| DBPCT * | List[int] | Input pseudocolor segment or layer | 1 - 1 |
| Back to top |
FILE
Specifies the name of the PCIDSK image file that contains the imagery to be compressed.
DBIC
Specifies the three 8-bit channels or layers that contain the RGB image to be compressed.
DBOC
Specifies the single 8-bit black and white channel or layer that receives the compressed image.
DBPCT
Specifies the PCT segment or layer that supplies the set of available colors to which the image is compressed.
| Back to top |
ERRDIFF compresses a 24-bit color (RGB) image into a single 8-bit channel, based on a PCT (segment type: 171) that you provide. The PCT is used to color a compressed image so that it looks similar to the original 24-bit color image. This capability can be used when preparing color images for exporting to other third-party software (for example, a GIS system with limited color capability).
ERRDIFF can be used when color images must be exported to other hardware or software systems without 24-bit color support.
The error diffusion algorithm used by ERRDIFF attempts to select a nearby color in the PCT, (but not always the nearest one) in proportions such that, at a distance (as the pixels merge visually), a better approximation of the color of a region is achieved.
The input file contains the input RGB channels and the channel to which to write the compressed result. If the imagery is to be enhanced with a lookup table (LUT), apply it to the RGB channels ahead of time with the LUT function.
The input RGB channels and the output compressed channel must be 8-bit because of the nature of a PCT. Although any type of image channel can be used, values are internally converted to 8-bit data. Using non 8-bit data can result in unexpected or poor results.
| Back to top |
Transfer a 24-bit color image to a GIS system to be used as a backdrop for digitizing vectors. The GIS system can only use 8-bit images in SUN Rasterfile format. Export the contents of /demo/map100.pix with the most appropriate PCT possible.
The ADAPT function generates a PCT well distributed to represent this particular image.
from pci.adapt import adapt file='map100.pix' dbic=[1,2,3] dbpct = [] # Default is to create new PCT segment dbsn = 'Adapt' # Name for new PCT segment dbsd = '' adapt(file, dbic, dbpct, dbsn, dbsd)
ERRDIFF is then used to transform the RGB image into a pseudocolor image, based on the adaptive PCT.
from pci.errdiff import errdiff file='map100.pix' dbic=[1,2,3] dboc=[1] dbpct = [3] # New PCT segment from ADAPT errdiff(file, dbic, dboc,dbpct)
The 8-bit image is now made into a SUN Rasterfile.
from pci.fexport import fexport
fili=file
filo="irvine.im8"
dbiw=[]
dbic=[1]
dbib=[]
dbvs=[]
dblut=[]
dbpct=[]
ftype='SUN'
foptions=''
fexport(fili, filo, dbiw, dbic, dbib, dbvs, \
dblut, dbpct, ftype, foptions)
The file map100.im8 can now be used by the GIS system.
| Back to top |
The error diffusion algorithm used by ERRDIFF is based on the concept of remembering the cumulative error in approximating the error for each pixel and attempting to err in the opposite direction in red, green, and blue image space for the next pixel.
For each pixel, the following process takes place.
P1 -- P2
/ | \
/ | \
P3 P4 P5
Finding the nearest color in the PCT to an RGB color is performed by building a large three-dimensional table with red, green, and blue values as the indices. This table is populated in advance with the nearest color for each possible RGB value to avoid computing by exhaustive comparison for each pixel in the image.
© PCI Geomatics Enterprises, Inc.®, 2026. All rights reserved.