← Back to course
2/6
Week 03 Β· Encoding the World

Tuesday

Colors as numbers
// Pixels, color values and feature tables
⏱ about 20 min

Tuesday: Colors as Numbers

Rocket opens the data file behind one snapshot pixel. Instead of a color, he finds three numbers in a row.

"Red, green and blue," Raven reads over his shoulder. "Every single pixel gets all three."

Rocket scrolls down. "Here is one that says 255, 255, 255. And here is one that says 0, 0, 0."

"The first one is a blazing white star," Nova says. "The second is the empty black sky around it."

Raven starts a list of the biggest and smallest numbers in the file.

"So brightness is hiding in the numbers," Rocket says. "That might be something Sky Sorter can use."

Red, green and blue

A screen makes each pixel's color by mixing red, green and blue light.

So a computer stores three values for each pixel: a red value, a green value and a blue value.

Each value runs from 0 to 255.

All three values at 255 make white. Lower values make a pixel darker, down to pure black at 0.

PixelRedGreenBlueWhat it looks like
1255255255White, like a blazing star
2000Black, like empty sky
3120120120Darker than 1, lighter than 2
READ THE VALUES
  • Read the question.
  • Tap your answer.
Which pixel is white?
Which pixel is black?
Which pixel is darker: 40, 40, 40 or 200, 200, 200?
What is the highest value a single color can have?
ORDER THESE PIXELS FROM DARKEST TO LIGHTEST
  • ?70, 70, 70
  • ?0, 0, 0
  • ?255, 255, 255
  • ?160, 160, 160
WHY THIS EXERCISELower values darken a pixel, so you can rank brightness from the numbers alone.
How many values does a computer store for each pixel? Type a number.
What is the lowest value a color can have? Type a number.
All three values at 255 make which color?

Two encodings for one snapshot

Three numbers from 0 to 255 per pixel is a lot to write by hand.

So the crew's paper snapshot cards use a simpler encoding: one brightness value per pixel.

It uses the same 0 to 255 scale, from 0 for black up to 255 for the brightest white.

This one-value code is the crew's own shortcut. It keeps brightness but throws away color detail.

Choosing an encoding is a trade-off. Simpler codes are faster to use but keep less information.

StatementTrue or false?
A computer stores a red, green and blue value for each pixel.?
Higher values make a pixel darker.?
The crew's one-value brightness code keeps all the color detail.?
A simpler encoding always keeps more information.?
WHY THIS EXERCISEKnowing what an encoding keeps and what it throws away helps you judge what a sorter can learn.
On the crew's brightness scale, what value means the brightest white? Type a number.
WHY THIS EXERCISEKnowing the top of a scale lets you read any value on it.
Try it
On graph paper, shade a 4 by 4 square using four pencil pressures: none, light, medium and heavy.
Write a code from 0 to 3 in each square to match. You have just invented an encoding.

Nice decoding. Tomorrow's Explorer Lab turns brightness values back into a snapshot.

← Monday