ERRDIFF

Compress Image with Error Diffusion


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

Back to top

Description


ERRDIFF compresses a 24-bit RGB image into a single 8-bit image, based on a pseudocolor table (PCT) that you provide. An error diffusion algorithm improves the quality of the output image. ERRDIFF can be used when color images must be exported to other hardware or software systems without 24-bit color support.
Back to top

Parameters


Name Type Caption Length Value range
FILE* String Input file name 1 - 192  
DBIC* Integer Input channels or layers 3 - 3  
DBOC* Integer Output channel or layer 1 - 1  
DBPCT* Integer Input pseudocolor segment or layer 1 - 1  
MONITOR String Monitor mode 0 - 3 ON, OFF
Default: ON

* Required parameter
Back to top

Parameter descriptions

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.

MONITOR

The program progress can be monitored by printing the percentage of processing completed. A system parameter, MONITOR, controls this activity.

Available options are:

Back to top

Details

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.

CMPRSS8 is based on selecting the nearest color in the PCT to represent each RGB pixel, based on the euclidean distance in the red, green, and blue dimensions. This is acceptable for some image types, but for RGB images with gradually changing colors, this method leads to noticeable banding effects. 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

Examples

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.

EASI>FILE = "map100.pix"
EASI>DBIC = 1,2,3
EASI>RUN ADAPT

ERRDIFF is then used to transform the RGB image into a pseudocolor image, based on the adaptive PCT.

EASI>DBIC = 1,2,3
EASI>DBOC = 1   ! Overwrites channel 1.
EASI>DBPCT=LASC ! Uses the newly created segment.

EASI>RUN ERRDIFF

The 8-bit image is now made into a SUN Rasterfile.

EASI>FILI = FILE! map100.pix
EASI>FILO = "map100.im8"
EASI>DBIC = 1
EASI>DBIW =
EASI>FTYPE="SUN"

EASI>RUN FEXPORT

The file map100.im8 can now be used by the GIS system.

Back to top

Algorithm

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.

  1. Subtract the RGB error values previously accumulated to the RGB input value for this pixel (P1) to give a modified target color (MP1).
  2. Find the nearest color in the PCT table to this modified RGB value (MP1) and designate the nearest color AP1.
  3. Subtract the RGB value of the selected entry in PCT (AP1) from the RGB value (MP1) to give a red, green, and blue error value.
  4. Add one sixth of the error to the error accumulations for the bottom-left (P3) pixel and the bottom-right (P5) pixel from this pixel. Add one third of the error to the pixel immediately below the current pixel (P4). Add the remainder of the error (approximately one third, depending on rounding) to the pixel to the right (P2) of the current pixel.

            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.®, 2024. All rights reserved.