An image is a table of numbers
A photo is a table of numbers: three per pixel, red, green and blue. See it on an apple and why its red is thousands of numbers. AI course, 0.2.

AI from the First Bit › Level 0 — How a machine sees the world part 2 of 9
- 1Everything is a number (yes, even your name)
- 2An image is a table of numbers
- 3A corrupted bit: how to fix it without knowing which one it is
- 4What is a model (and why a straight line already counts as one)
- 5Finding a path: an AI that learns nothing
- 6Playing against a machine: minimax and alpha-beta pruning
- 7How far a machine looks: the horizon effect and deciding with less
- 8Deciding by playing at random: Monte Carlo and Hex
- 9How a video game character decides: states, trees and scores
To a computer, a photo is a table: rows and columns of cells, and in each cell three numbers, one per color. And on the skin of an apple those numbers change so much from one area to another that the same red is thousands of different triplets.
Try this first
Open this apple in the Images tool. On the left you will see the photo; on the right, a table of 8 × 8 cells, each painted in its own color and with three numbers inside. Each cell is a pixel, one of the dots the image is made of, and its three numbers say how much red, how much green and how much blue it has, from 0 to 255. Click anywhere else on the apple and the table changes to the pixels in that area.

Now compare two areas of the same red skin. Open the part where the light hits it: the numbers hover around 205, 127, 104. And now the edge that stays in shadow: they hover around 121, 1, 13.
Scroll down to The three channels, separately and together. The same apple appears four times: three in gray and one in color.
What just happened
Each pixel stores three numbers, one per color, and each goes from 0 to 255: 256 possible values, exactly what fits in one byte (8 bits). With three numbers like that you get 256 × 256 × 256 = 16,777,216 different colors. The apple photo is 480 × 433 pixels, so that is 207,840 pixels and 623,520 numbers. Those 623,520 numbers are the whole photo.
Why three colors and not two or five? Because the human eye has three types of cones, the cells that tell colors apart, and each type is most sensitive to a different part of the light: short, medium and long wavelengths (Cone cell, on Wikipedia). A screen takes advantage of that: by mixing just three lights, in the right proportion, it makes the eye see a very wide range of colors.
The channels are those three tables taken separately. In each gray image there is only one number per pixel: white is 255 (a lot of that color) and black is 0 (none). In the R channel the apple comes out almost white, because it has a lot of red; in G and B it comes out almost black. The fourth image puts together the three numbers of each pixel and the color photo comes back.
One detail, because Images also has a Base64 tab (a way of writing any bytes with letters and numbers, so they can be pasted as text): what shows up there are the bytes of the compressed file (a JPEG, a PNG), which stores the image far more compactly, not this table. To get to the pixels you have to decompress it, which is what the tool does before showing them to you.
The classic mistake
You might think color is a property of the apple: the apple is red, and that is that. To the computer, it is not. Put the two triplets from before side by side: in the light, 205, 127, 104; in the shadow, 121, 1, 13. All three numbers change. The red drops from 205 to 121, and the one that changes most is the one you would least expect on a red apple: the green, which goes from 127 to 1. They are two triplets that look nothing alike, and both are “the apple’s red”.
A program that looked for apples by “the red number” would fail as soon as the light changed. What has to be recognized is a shape: a pattern across many neighboring pixels (how that is done is covered in Convolution).
Try it yourself
In the apple in the Images tool, next to the stem, there is a yellow area. Before clicking on it, make a guess: what numbers do you expect? Which of the three will be the lowest? Click and check. Then switch from RGB to R, G and B with the buttons above the table and see which channel keeps almost everything.
Test yourself
Open the yellow area next to the stem and look at the first pixel in the table (x 200, y 80). What is its blue value?
B = ___. On a screen, yellow comes from mixing red with [green / blue / white].
Each cell of the table is three numbers: R, G and B, in that order.
See the answer
Answers: 2 and green.
That pixel is R 190, G 165 and B 2: a lot of red, a lot of green and almost no blue. On a screen light adds up, and red plus green gives yellow. With paint it would be the other way around: mixing red and green gives a brown, because paint subtracts light.
Then open the Color HEX/RGB/HSL tool and type the two triplets from before, one after the other: rgb(205,127,104) and rgb(121,1,13). The tool converts them to another way of describing a color, HSL (hue, saturation, lightness). Which of the three numbers changes least between the lit area and the shaded one? What does that tell you about what “red” means? (A hint: the hue is an angle on the color wheel, from 0 to 360, so 354 is very close to 0.)
Test yourself
In the Color HEX/RGB/HSL tool, which of the three HSL numbers changes least between the lit area, rgb(205,127,104), and the shaded one, rgb(121,1,13)?
- The hue (H)
- The saturation (S)
- The lightness (L)
See the answer
The answer is A.
The lit area is hsl(14, 50%, 61%) and the shaded one hsl(354, 98%, 24%). The hue seems to change a lot, from 14 to 354, but it is an angle: on the color wheel they are only 20 degrees apart, both in the red. Saturation goes from 50 to 98%, and lightness from 61 to 24%. What we call “red” is mostly the hue; light changes the other two.
And if you like, in Images you can load a photo of your own and see its numbers.
Further reading
- On Jarroba, Binary: Combinations and Conversion explains the RGB model with its 24 bits per pixel (8 per channel), and in What Is Clustering? Ricardo Moya uses hair color in RGB as the data for a machine learning example.
- RGB color model, on Wikipedia: the physical principles behind it, its numeric representation and its use in web design.
“An image is a table of numbers” by Ramón Invarato at jarroba.com, licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0. Registered at Safe Creative.

You may also like
Is my improvement real? When a difference is more than chance
Your change raises the metric: real improvement or chance? A/B testing, the p-value and the mistake of peeking at results too early. AI course, 1.4.
A sample is not the whole truth: minimal statistics
Why the number from a sample is not the true one, how much it changes, and why pure chance can look like a trend. AI course, 1.3.





Leave a comment