RGB2PCT

Compress Image using PCT


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

Back to top

Description


Takes a 24-bit RGB image and compresses it into a single 8-bit image, based on a defined Pseudocolor Table (PCT). For each pixel in the input image, this function establishes the nearest color in the supplied PCT, and places a corresponding color index in the output channel. This capability is useful when exporting color images for hardware/software systems that do not support 24-bit color.
Back to top

Parameters


rgb2pct(file, dbic, dboc, dbpct)

Name Type Caption Length Value range
FILE * str Input file name 1 -    
DBIC * List[int] Input raster channel(s) or layer(s) 3 - 3  
DBOC * List[int] Output raster channel(s) or layer(s) 1 - 1 1 - 1024
DBPCT * List[int] Pseudocolor Layer 1 - 1  

* Required parameter
Back to top

Parameter descriptions

FILE

Specifies the name of the file that contains the input data to be processed.

DBIC

Specifies the three 8-bit channels in the RGB image.

DBOC

Specifies the single 8-bit output channel in which to store the compressed image.

DBPCT

Specifies the Pseudocolor Table (PCT) segment used to define the set of available colors to which the image should be compressed.

Back to top

Details

RGB2PCT compresses a 24-bit color (RGB) image into a single 8-bit channel based on the specified pseudocolor table (PCT, segment type: 171). The pseudocolor table is used to color the compressed image so that it looks similar to the original 24-bit color image. This capability is useful when preparing color images for export to other third-party software systems with limited color capability.

The input file (FILE) contains the input RGB channels (DBIC) and the channel to which to write the compressed result (DBOC).

Due to the 8-bit nature of a pseudocolor table, the input RGB channels and the output compressed channel must be 8-bit. While any type of image channel may be used, values are internally converted to 8-bit data. Using non 8-bit data may result in unexpected or poor results.

Note: If the imagery is to be enhanced with an LUT, this should be applied to the RGB channels ahead of time using the LUT function.
Back to top

Examples

The user wishes to transfer a 24-bit color image to a GIS system, to be used as a backdrop for digitizing vectors. The GIS system supports only 8-bit images in SUN Rasterfile format. We would like to export the contents of /demo/map100.pix with the most accurate Pseudocolor Table possible.

The ADAPT function is used to generate a PCT well distributed to represent this particular image.

from pci.adapt import adapt

file='map100.pix'
dbic=[1,2,3]           # RGB image
dbpct = []             # Default is to create new PCT segment
dbsn = 'Adapt'         # Name for new PCT segment
dbsd = ''

adapt(file, dbic, dbpct, dbsn, dbsd)
            

RGB2PCT is used to transform the RGB image into a Pseudocolored image, based on the adaptive PCT (segment 3).

from pci.rgb2pct import rgb2pct

file='map100.pix'
dbic=[1,2,3]           # RGB image
dboc = [1]
dbpct = [3]            # new PCT segment 3

rgb2pct(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]                    # channel from map100.pix
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.

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