Images as numbers
To a computer, a photo is a grid of numbers — three per pixel for color. Zoom into an image until you can read its values, split it into channels in 3D, and see why brightness, contrast and grayscale are just arithmetic.
In this lecture you will
- Describe how a digital image is stored as a grid of pixels
- Explain RGB channels and the value range of each pixel
- Read an image’s shape as height × width × channels, and a batch as a 4D tensor
- Apply simple pixel operations such as brightness, contrast and grayscale conversion
Computer vision gives machines the ability to understand images and video: reading documents, inspecting products on a production line, spotting tumours in scans, counting cars or recognizing faces. Every one of these systems starts from the same raw material, and it is much humbler than a picture: a grid of numbers.
Zoom in until the picture disappears
The image below was drawn by code for this course — a house, a tree and a car. Drag the lens across it. On the right you see the 64 pixels under the lens, with the three numbers stored for each.
Each pixel stores a red, green and blue intensity from 0 to 255. The sky pixels have high blue values; the road is a low, even gray; the car body is strongly blue.
Each pixel records how much red, green and blue light to show. Mixing them produces every color on your screen: (255, 0, 0) is pure red, (255, 255, 0) is yellow, (128, 128, 128) is mid-gray. With 256 levels per channel, a pixel can take 256³ — about 16.7 million — different colors.
- Pixel
- The smallest element of a digital image: a single colored point in the grid.
- Resolution
- The number of pixels, written width × height — for example 1920 × 1080.
- Channel
- One layer of the image that stores a single component, such as the red intensity of every pixel.
- Bit depth
- How many values each channel can take. 8 bits gives 256 levels (0–255), the common default.
- Tensor
- A multi-dimensional array of numbers. An image is a 3D tensor; a batch of images is 4D.
Channels and tensors
A color image is not one grid but three stacked grids — one per channel. Deep-learning frameworks store it as a tensor with shape height × width × channels.
- One color imageOn screen, an image looks like a single picture: 160 pixels wide and 110 pixels high.
- Three channelsStored in memory, it is three grids of the same size: the red, green and blue intensity of every pixel. Its shape is 110 × 160 × 3.
- One pixel, three numbersFollow one pixel on the car through the three planes: a low red, a medium green and a high blue value — which the eye sees as blue.
- Grayscale: one channelA weighted average of the channels gives brightness alone. Green counts most because human eyes are most sensitive to it.
- A batch is a 4D tensorModels process many images at once. A batch of 32 images has shape 32 × 110 × 160 × 3 — batch, height, width, channels.
Image editing is arithmetic
Because pixels are numbers, editing an image means doing arithmetic on them. Brightness adds a constant to every value; contrast multiplies each value’s distance from mid-gray; grayscale takes a weighted average of the channels; inverting computes 255 − value.
The histograms count how many pixels have each value. Brightness slides a histogram sideways; contrast stretches or squeezes it. Values pushed past 0 or 255 are clipped — that detail is lost.
Try Red only: the sky becomes dark, because sky pixels have little red. Then Blue only: the sky is bright and the tree almost vanishes. Each channel holds different information about the scene — and a neural network looks at all of them.
Before a model sees an image
Real pipelines prepare images in the same way, every time:
- Resize to the size the model expects, such as 224 × 224.
- Scale values from 0–255 to 0–1.
- Normalize each channel by subtracting its average and dividing by its spread, so all channels have a similar range.
from PIL import Image
import numpy as np
img = Image.open("scene.png").convert("RGB").resize((224, 224))
x = np.asarray(img, dtype=np.float32) / 255.0 # shape (224, 224, 3), values 0..1
mean = np.array([0.485, 0.456, 0.406]) # ImageNet channel means
std = np.array([0.229, 0.224, 0.225])
x = (x - mean) / std # normalized, ready for a model
print(x.shape, x.min(), x.max())
A single pixel tells you almost nothing. Meaning — an edge, a corner, a wheel — lives in neighborhoods of pixels. The next lecture introduces the operation that reads neighborhoods and powers every modern vision model: convolution.
Key takeaways
- A digital image is a grid of pixels; each pixel is a small set of numbers.
- Color images usually have three channels — red, green and blue — each stored as 0–255 or rescaled to 0–1.
- Images are tensors with shape height × width × channels; models process batches, adding a fourth dimension.
- Many image adjustments are simple arithmetic on those numbers, and models see nothing but the numbers.
Check your understanding
4 questions · answers explainedQ1How many numbers are needed to store a 1920 × 1080 color image in RGB?
Q2A pixel has the RGB values (255, 255, 0). What color is it?
Q3A batch of 32 color images, each 224 × 224, is fed to a model. What is the shape of the input tensor (in batch, height, width, channels order)?
Q4Why does increasing contrast make an image look sharper, in terms of pixel values?