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.
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.
The advantages of using a color data structure are mainly three:
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.
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.
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.
Applying this color table to the labeled image yields
There are three ways to work with color tables: