CMPRSS8 -- Compress 24-Bit Image to 8-Bits

Takes a 24-bit RGB image and compresses it down into a single 8-bit image using a simple colour cube for quantization. CMPRSS8 also produces a pseudocolour table (PCT) segment that can be used to show the 8-bit result in (close to) original colours.

This capability is useful when colour images have to be exported to other hardware/software systems which do not have 24-bit colour support.

The ADAPT and PCTMAKE programs are similar, but compute PCTs better adapted to a particular image. Then the ERRDIFF or RGB2PCT programs can be used to convert the RGB images to one channel.

Progress of this program can be monitored. See MONITOR section.

See Also: PCXWRIT, PCTWRIT, PCTMAKE, RGB2PCT, ERRDIFF, ADAPT

PARAMETERS

CMPRSS8 is controlled by the following global parameters:

Name     Prompt                                  Count     Type
FILE     Database File Name                      1-64      Char
DBIC     Database Input Channel List             3         Int
DBLUT    Database Lookup Table Segment           0-3       Int
DBOC     Database Output Channel List            1         Int
RGBLEVEL Output Compression Levels: R,G,B        3         Int
DBPCT    Database Pseudocolour Segment           0-1       Int
DBSN     Database Segment name                   0-8       Char
DBSD     Database Segment Descriptor             0-64      Char

The following parameter receives output:

DBPCT    Database Pseudocolour Segment           0-1       Int

FILE

Specifies the name of the PCIDSK image file containing the imagery to compress.

 EASI>FILE="filespec"

DBIC

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

 EASI>DBIC=r,g,b

DBLUT

Optionally specifies LUTs that can be used to enhance the RGB channels specified in DBIC.

 EASI>DBLUT=i,j,k               | use LUTs to enhance
 EASI>DBLUT=                    | no enhancement, use raw RGB

DBOC

Specifies the 8-bit channel to receive the compressed image.

 EASI>DBOC=i

RGBLEVEL

Specifies the number of red, green, and blue output levels that should be used in the compression. The product of these three values must be less than 256 (i.e., redlevels * greenlevels * bluelevels < 256).

 EASI>RGBLEVEL=redlevels,greenlevels,bluelevels
The following are typical settings:

 EASI>RGBLEVEL=6,6,6            | total 216 values
 EASI>RGBLEVEL=5,9,5            | total 225 values
 EASI>RGBLEVEL=7,7,5            | total 245 values

DBPCT

Specifies the database pseudocolour table (PCT) segment number to receive data. If no segment number is specified then a new segment is created.

 EASI>DBPCT=n                   | overwrite PCT segment n
 EASI>DBPCT=                    | create a new segment
If a new segment is created then DBPCT is updated with the created segment number when the program completes.

DBSN

Specifies a 1 to 8-character quick identifier for the new pseudocolour table.

 EASI>DBSN="string"
This value is only used if a new pseudocolour table segment is created.

DBSD

Specifies a 1 to 64-character descriptor of the contents or origins of the new pseudocolour table.

 EASI>DBSD="string"
This value is only used if a new pseudocolour table segment is created.

DETAILS

CMPRSS8 compresses 24-bit colour (RGB) images into a single 8-bit channel and also creates a pseudocolour table (PCT, segment type: 171), which can be used to colour the compressed image so it looks similar to the original 24-bit colour image. This capability is useful when preparing colour images for export to other third party software systems (for example a GIS system with limited colour capability).

The input file (FILE) contains the input RGB channels (DBIC) and the channel to which to write the compressed result (DBOC). An enhancement can be applied to the RGB channels by the use of previously saved lookup tables (DBLUT) held in segments on the input file. The generated PCT is saved in a segment on the input file. This can either overwrite an existing PCT or a new segment can be created (DBPCT). If a new segment is created then an 8-character identifying name (DBSN) and a 64-character descriptor (DBSD) are assigned to it.

A value of black (0,0,0) is assigned to entries in the PCT for which the respective image values are not required in the compression.

The input RGB channels and the output compressed channel should be 8-bit. This restriction is due to the 8-bit nature of a pseudocolour table. While any type of image channel can be used, values are internally converted to 8-bit data. Using non 8-bit data may result in unexpected or poor results.

CMPRSS8 is not intended for compressing Black and White imagery.

MONITOR

Program progress can be monitored by printing the percentage of completed processing in odometer fashion. A system parameter, MONITOR, controls this activity:

EASI>MONITOR="ON"           | turn monitor ON  (default)
EASI>MONITOR="OFF"          | turn monitor OFF (recommended if
                            | running in batch/background mode)

ALGORITHM

The compression scheme used in CMPRSS8 was picked for simplicity and speed.

Each colour band is reduced from 256 grey levels to the number of grey levels specified in the RGBLEVEL parameter. Typically this is 10 or less. The generated pseudocolour table maps each of these new grey levels onto a reasonable intensity representing all the original grey levels. For example, suppose the number of output grey levels is 4 for a channel, then:

     input grey levels     output level     intensity

         0 -  63                 0               0
        64 - 128                 1              85
       129 - 192                 2             170
       193 - 255                 3             255
The output intensities always span 0 to 255 to ensure that the greatest dynamic range of colours is used. Using the mid point of each range (say 32 rather than 0) may be more faithful but doesn't look as good.

Once the grey levels have been reduce and the output intensities for each colour determined, the values are encoded into a single 8-bit image channel and corresponding pseudocolour table. The following code fragments show this algorithm.

Image Compression

  for each pixel
      newred   = integer((redPixel  *redLevels)  / 256)
      newgreen = integer((greenPixel*greenLevels)/ 256)
      newblue  = integer((bluePixel *blueLevels) / 256)
      encodedPixel  = newred + newgreen*redLevels
                             + newblue *redLevels*greenLevels
  endfor
Pseudocolour Table Generation

  i = 0
  for blue = 0,bluelevels-1
      blueIntensity = (blue*255) / (blueLevels-1)
      for green = 0,greenLevels-1
          greenIntensity = (green*255) / (greenLevels-1)
          for red = 0,redLevels-1
              redIntensity = (red*255) / (redLevels-1)
              PCT[i] = redIntensity, greenIntensity, blueIntensity
             i = i + 1
          endfor
      endfor
  endfor
To print out the results of these calculations on actual data, use the programs NUM and PCTREP.

EXAMPLE

The user wishes to transfer a 24-bit colour 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. The file irvine.pix contains the RGB image in channels 3,2,1 and lookup tables in segments 4,3,2. First the image is compressed to 8-bit.

 EASI>FILE = "irvine.pix"
 EASI>DBIC = 3,2,1
 EASI>DBLUT= 4,3,2
 EASI>DBOC = 7
 EASI>RGBLEVEL = 5,8,5
 EASI>DBPCT=                            | will contain new segment #
 EASI>DBSN = "RGB8bit"
 EASI>DBSD = "RGB for 8-bit compression"
 EASI>RUN CMPRSS8
The 8-bit image is now made into a SUN Rasterfile.

 EASI>FILI = FILE                       | irvine.pix
 EASI>FILO = "irvine.im8"
 EASI>DBIC = DBOC                       | 7
 EASI>DBIW =
 EASI>DBLUT=
 EASI>FTYPE="SUN"
 EASI>RUN FEXPORT
The file irvine.im8 can now be used by the GIS system.


About PCI Help Gateway