Nature Photographers Network
This is the preserved archive of the original Nature Photographers Network. The community continues at naturephotographers.network.

COLOR BY THE NUMBERS

Discussion

3 replies
Posted by Doyle Thomas on May 13, 2007 at 11:57 PM
COLOR BY THE NUMBERS
COLOR BY THE NUMBERS
Gary Doyle Thomas
Primary Focus Photography
Copyright protected 2007

PhotoShop uses numbers to represent colors. In the early days of modern computers their main usage was to deal with the complex simultaneous equations required for calculating artillery trajectories. It was Alan Turing (British, 1912-1954) who first proposed the thought that any idea or symbol that could be represented by a number could be programmed into a computer. This profound concept led to using numbers to represent the letters of the alphabet and made it possible to use computers to bust into the secrete codes of World War II. Each letter corresponds with a numeric value in a look-up table. The most common look-up table in use today is called ASCII, which means American Standard Code for Information Interchange.

The look-up table in PhotoShop is called a color space and there are many. Examples include AbobeRGB, sRGB, and AppleRGB. Each of these color spaces is designed to represent a portion of the spectrum of visible light. While the spectrum of visible light is not infinite the human eye can perceive more nuance of color hue and brightness than can be represented in a color space. This is because the look-up table can only define 16,777,216 colors. Any given color space seeks to create a subset of the spectrum of visible light using 16,777,216 symbols. This is called a gamut and it defines the palette of available colors.

To understand why the color space is limited to 16,777,216 colors you must understand how numbers are represented inside a computer. A computer is nothing more than a fancy light switch. It only knows two things, ON, and OFF. This is known as binary logic and because the computer can be ON or OFF very fast it can accomplish work quickly. Decimal numbers must be converted to binary where the computer can use them and then converted back to decimal for output. The computer treats the value of a number differently than the symbol for that number.

What do the symbols mean? The drawing above shows the original way in which decimal number symbols were made. Note that the value for each symbol is equal to the number of angles in that symbol. Arabic numerals, known formally as Hindu-Arabic numerals are the most common symbolic representation of numbers around the world. They are considered an important milestone in the development of mathematics. The true elegance of the system is that the symbol for zero has no angles.

How do we read a decimal number? Recalling our first grade math we read numbers in columns. The rightmost column is the ones, then the tens, hundreds, thousands, and so on. Decimal means ten and there are ten symbols. Table #1 below shows the values for each column and how they are calculated. These values are so drilled into us during our early education that they become innate and we rarely think about them.

TABLE #1 DECIMAL
10 ^7= 10000000 10 ^6 = 1000000 10 ^5= 100000 10 ^4= 10000 10 ^3= 1000 10 ^ 2= 100 10 ^ 1= 10 10 ^ 0= 1





Binary means two and there are two symbols. Table #2 below shows the values for each column and how they are calculated.

TABLE #2 BINARY
2 ^ 7= 128 2 ^ 6= 64 2 ^ 5= 32 2 ^ 4= 16 2 ^ 3= 8 2 ^ 2= 4 2 ^ 1= 2 2 ^ 0= 1


Finding the value for a row of symbols is the same in both cases. For example, using the decimal value 5284(d) and Table #1:

For the 1st column we have 4 * 1 = 4
For the 2nd column we have 8 * 10 = 80
For the 3rd column we have 2 * 100 = 200
For the 4th column we have 5 * 1000= 5000
Adding them together we get 5284(d)



Binary values are found in the same way, for example using the binary value 1101(b) and Table #2:

For the 1st column we have 1 * 1 = 1
For the 2nd column we have 0 * 2 = 0
For the 3rd column we have 1 * 4 = 4
For the 4th column we have 1 * 8 = 8
Adding them together we get 13(d)

All PhotoShop RGB color spaces are represented by 24 bits (CYMK color spaces are beyond the scope of this document). Eight bits each for red, green, and blue. The binary values for each color range from 00000000(b) to 11111111(b).

00000000(b) is zero and is equal to 0(d) of course but lets see what 11111111(b) is in decimal:

For the 1st column we have 1 * 1 = 1
For the 2nd column we have 1 * 2 = 2
For the 3rd column we have 1 * 4 = 4
For the 4th column we have 1 * 8 = 8
For the 5st column we have 1 * 16 = 16
For the 6nd column we have 1 * 32 = 32
For the 7rd column we have 1 * 64 = 64
For the 8th column we have 1 * 128 = 128

Adding them together we get 255(d)

Because in the computer zero is a counting value there are 256 decimal values that can be represented by eight binary bits. 256 reds, 256 greens, and 256 blues.

256 * 256 * 256 = 16,777,216
Posted by Guy Tal on May 14, 2007 at 8:30 AM
Doyle, I don't think this article is quite correct. The number of bits in RGB numbers is not related to color spaces. The color space defines the available gamut. The RGB numbers represent degrees of gradation within that space. So, the same color space can be used with 8-bits per channel or 16-bits per channel or more.

The color space defines what shade a given number represents, so for example 11,22,33 will have a slightly different look in Adobe RGB than it will in sRGB, and so on.

When performing color-space conversion, colors in the source space need to be mapped to colors in the target space, which means their RGB values will change to the closest color in the target. In other words - the numbers are only meaningful within a given space. They are not universal representations of the same color.

Also, Photoshop is quite capable of representing each of the RGB channels in 16-bit and 32-bit, meaning for example that 255,255,255 (pure white) in 8-bits is the same as 65535,65535,65535 in 16-bit and so-on. For convenience the information palette will normalize the numbers to 8-bits even when working in higher bit rates.

Guy
Posted by David Bostedo on May 14, 2007 at 12:36 PM
To add to what Guy said (or rather, post some questions relating to what Guy said) -

Isn't the gamut determined by the colors that devices are capable of representing and the steps in between? i.e. there isn't really a choice to discard colors because of some numberical limit in the total number of colors. Rather, the limit on gamut is chosen based on what devices can usually display.

The gamut of sRGB, then, could cover ever visible color, but at the cost of possibly spreading out the steps and fine gradations that can be shown. Thus, a smaller gamut was chosen to use for sRGB to either match what displays, printers, etc were capable of showing, or to force finer gradations, or both.
Posted by Guy Tal on May 14, 2007 at 1:16 PM
David, that's exactly right. The profile is a representation of the color gamut the device is capable of reproducing (which has nothing to do with the number of bits used to represent each color).

sRGB was originally developed as a universal color space (kind of a lowest common denominator for a variety of devices) which is why it is a good choice for generic web display etc.

In the conversion process, if numbers in the source space represent colors that are out of gamut in the target space they are either discarded or remapped to the closest available color (depending on the conversion intent).

Guy