Color Table

The pixel values of a digital image can be a single scalar value or a vector with its values normally called elements or attributes. In color images each pixel has three elements. What the three elements mean dependends on the color model used. In the RGB color model, the three elements correspond to the colors Red, Green and Blue.

There are two data structures used to represent the pixels values within an image. One is called True Color and the other a Color Table.

In the True Color data structure each pixel is stored in the standard form within the image matrix. In the Khoros system, it is stored in the VALUE segment of the image data structure.

Value data model

In the Color Table data structure, each pixel value is an index to the table (look-up table). Each entry on the table can have one or more elements. The length of the table can be of any size and depends on the index values within the image. There are many names for the color table, some are: color palette, LUT (look-up table), mapping table, colormap. In the Khoros system, the color table is stored in the MAP segment of the image data structure.

Colormap data model

The advantages of using a color data structure are mainly three:

  1. Image Compression In a true color image it is required three values for each pixel. If a color table is used, each pixel can have just one value and index a table of width 3 representing the number of possible colors in the image. An image with a color table is approximately 1/3 the size of the true color image.
  2. Processing Speed If an image is represented using a color table data structure, all point operations using a single operand can be done only by processing the color table. The color table is in general much smaller than the image.
  3. Hardware Support Most color monitors and frame grabbers have a color table in hardware so that the color table structure matches the hardware model very well.

In this experiment a color table is built to solve the problem of coloring a black and white Unicamp logo below into a colored one like, with its three red dots.

a)Black and White logo; b)Colored logo
a) b)

The idea is to first label the image, such that a unique value is assigned to each pixel belonging to a connected region. Normally, the labeling process assigns region numbers in a ascending order so that the maximum number corresponds to the the number of connected region.

Labeled image: grey

The maximum pixel value of the labeled image is 23, so there are 24 regions: 0 is the background and 1 to 23 are the other connected regions. Use the mouse to identify the pixel values corresponding to the three small circles of the logo. These values are: 1, 10 and 16.

A color table can be built to assign pixel values 0 the color white, pixel values 1, 10 and 16 the color red, and the rest to black.

The color table using the RGB model is (the index column is implicit and not needed):

index R   G   B        color
-----------------------------
0     255 255 255      white
1     255 0   0        red
2     0   0   0        black
3     0   0   0        black
...
9     0   0 0 0        black
10    255 0   0        red
11    0   0   0        black
...
15    0   0   0        black
16    255 0   0        red
17    0   0   0        black
...
23    0   0   0        black

The color table can be visualized below. There are 24 colors in the table. Counting from the left corner we see that index zero corresponds to the color white, index values 1, 10, 16 to red and the rest to black.

Display of color table

Applying this color table to the labeled image yields

a)Labeled image; b)After applying the color table
a) b)

There are three ways to work with color tables:

  1. Use the color table only during display.
  2. Store the color table in the same file together with the pixel data.
  3. Explicitly mapping the image pixel into the color table, resulting in a true color image.