Color image
In a color image, we demonstrate that color can be expressed as a linear combination of three primary colors, for example, Red (R), Green (G), and Blue (B). Thus, any color x is expressed as x = aR + bG + cB, where a, b, c are doses of the primary colors. Each of these elements has shades ranging from 0 to 255: 256 colors. To represent 256 colors, it takes 8 bits, which is 1 byte. Since there are three different RGB elements, we thus need 3 bytes to account for all the nuances[1].
The RGB (or RGB in English) coding is used in many digital devices (scanners, cameras, screens, etc.). The principle is simple: one byte is used to code a number between 0 and 255 (hence 256 values), which corresponds to the value of the red, green, or blue component of the pixel (0 being the absence of this component, and 255 the saturation). The combination of these three components produces the final color.
The 24 bits of a color are broken down into 3 sets of 8 bits, meaning 3 bytes:
8 bits are dedicated to the red primary hue.
8 bits are dedicated to the green primary hue.
8 bits are dedicated to the blue primary hue.
Usually, a good image corresponds to doses ranging from 0 to 255. Consequently, an image of this type can be represented by 3 matrices (one for each primary color), each with elements of 8 bits, totaling 24 bits per pixel. We quickly realize the data volume for large and high-definition images. A 640x480 color image (24 bits) occupies a volume of 921,600 bytes. This leads us to use compression techniques to reduce the size of image files.
One of the early display standards, the CGA standard, allowed the display of pixels in a palette of 4 different colors. For this, each pixel had to be coded with 2 bits.
For example:
Decimal | Binary | Color |
0 1 2 3 | 00 01 10 11 | Black Green Red Yellow |
Then,increase. Now, we can have images with 16 colors. Since 16 = 24, it is sufficient to code each pixel with a sequence of 4 bits. Here is an example of a common palette:
Decimal | Binary | Color | Decimal | Binary | Color |
0 1 2 3 4 5 6 7 | 0000 0001 0010 0011 0100 0101 0110 0111 | Black Blue Green Cyan Red Magenta Brown Gray | 8 9 10 11 12 13 14 15 | 1000 1001 1010 1011 1100 1101 1110 1111 | Dark Gray Light Blue LightGreen LightCyan Light Red LiMagentaYellow White |
We can continue this way to discover images with increasingly sharp details thanks to their large number of colors: with 8 bits per pixel, we get 256 colors (since 28 = 256); with 16 bits, 65,536 colors; with 24 bits, over 16 million colors; with 32 bits, over 4 billion. From 24 bits onward, we refer to it as true-color display, given how perfect the realism is. In this context:
1 bit: 21 possibilities: black and white image
2 bits: 22 possibilities: 4 colors
4 bits: 24 possibilities: 16 colors
8 bits: 28 possibilities: 256 colors
24 bits: 224: 16,777,216 million colors