IMAGE commands


PROGRAM NAME

igamut - Compress Color Multiband Image to Single Band with Map

DESCRIPTION

igamut takes a up to a 4 band multi-spectral image, where each band would normally represent one component of a 24-bit color image (RGB, for example), and generates a pseudo color image with a specified number of colors that can be displayed. The object is to make the quantized image look like the original 24-bit image even though the number of colors is greatly restricted.

The quantization is performed by isolating clusters of "neighboring" color vectors in a three dimensional histogram, with each axis being one of the color components. The clusters are obtained using a modified version of Heckbert's median cut. The true colors are then matched to the closest cluster, and the input RGB triplet is then re-mapped to an n-color pseudo color image.

To keep the histogram from becoming exceedingly large (max of around 2^24 bytes), one may need to quantize the grey levels of the input bands to less than 8 bits. 6 bits (64 levels) gives results that are reasonable in a short amount of time. The number of bits that are kept is called the color precision, which can be specified at execution time. The general tradeoff is that smaller precision is faster and takes less memory, but it looks worse too. High precision takes longer and great gobs of memory, but looks decent, provided that a reasonable number (say 128 or more) colors is specified. The execution time is very dependent on the image statistics. In general, a small number of colors is faster than a large number of colors. In either case, if the image has good spatial color coherence, execution time is greatly reduced.

The allocation fraction (-r) controls how large areas of nearly the same color are handled. An allocation fraction of 0.0 will cause the large areas to be broken into as many colors as possible with the largest areas of a particular color range being broken first. An allocation fraction of 1.0 will attempt to preserve the detail in the image by preserving the color range of all parts of the image at the expense of smooth coloring of the larger areas. An allocation fraction of around 0.2 to 0.5 gives very good results on most images.

As a special note, be sure that the input image has a map that has one-to-one correspondence to the pixel values (i.e. the pixel value is the grey level). If this is not the case, use kmapdata(1) to convert to a linear map.

If the input image contains less than the number of colors requested then the output image will contain only the number of colors present in the input image. The color map will contain the number of entries requested (meaning all colors in the image) with any extra entries zero padded.

No dithering is done by igamut. Dithering in color space can often cause the image to look very noisy due to the color sensitivity of the eye. The result images from igamut may display some banding effects (Mach bands), but these are often more tolerable visually than the noise that would result from a color dithering process. (Should someone be suddenly inspired, there is enough information stored in the internal data structures to permit detection of Mach bands and automatic suppression of these artifacts; a few hundred more lines of C code should suffice to accomplish this.) Adding a small amount of noise to the image before using igamut can reduce Mach band effects greatly.

If the KHOROS_NOTIFY environment variable is set to KSYSLIB, then an additional diagnostic message, the number of colors actually found in the image, will be printed. The color count is subject to the color precision specified by the (-p) option.

Multiple plane images are processed by quantizing each plane independently, generating a corresponding plane of colors in the map. Thus an input object with (w,h,d,t,e)=(512,480,10,10,4) will result in an output object with a value segment with dimensions (512,480,10,10,1) and a map segment with dimensions (4,10,10,10,1).

REQUIRED ARGUMENTS

-i
type: infile
desc: Multiband input image (elements dimension > 1)
-o
type: outfile
desc: output file

OPTIONAL ARGUMENTS

-n
type: integer
desc: Number of colors to compress down to
default: 240
bounds: value > 0
-p
type: integer
desc: Number of bits of precision to use in each band during quantization
default: 8
bounds: 0 < [-p] < 8
-r
type: float
desc: Fraction of color splits based on subspace 2-norm
default: 0.5
bounds: 0 < [-r] < 1

EXAMPLES

% igamut -i lizard.rgb.viff -o lizard.240.viff -n 240 -p 8

quantizes the colors present in the 24-bit RGB input file down to 240 colors, using all 8 bits of each band of the input image.

SEE ALSO

kmapdata(1)

RESTRICTIONS

REFERENCES

The reference on which this routine is based is: P. Heckbert, "Color Image Quantization for Frame Buffer Display", Computer Graphics, Vol. 16, No. 3, July 1982, p297.

COPYRIGHT

Copyright (C) 1993 - 1997, Khoral Research, Inc. ("KRI") All rights reserved.