Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!
How Computers Work With Images
A human sees a cat in a photo. A computer sees a grid of numbers. Understanding this fundamental difference is the foundation of all Computer Vision.
Images Are Just Numbers
When you look at a photograph, you see colours, shapes, and objects. A computer sees something completely different: a large grid of numbers.
Every image is stored as a matrix (a grid) of numbers. Each number (or group of numbers) represents the colour of one tiny dot in the image — called a pixel.
For a black-and-white image:
- Each pixel is a single number from 0 (black) to 255 (white)
- 128 is a medium grey
For a colour image:
- Each pixel is three numbers: one for Red, one for Green, one for Blue
- These three numbers combine to create any colour
Machine Learning follows a structured pipeline from data to deployment
Seeing What the Computer Sees
import cv2
import numpy as np
# Create a tiny 4x4 grayscale image manually
# Each number is a pixel brightness: 0=black, 255=white
tiny_image = np.array([
[0, 0, 0, 0 ],
[0, 255, 255, 0 ],
[0, 255, 255, 0 ],
[0, 0, 0, 0 ]
], dtype=np.uint8)
print("This tiny image looks like a white square on a black background.")
print("But to the computer, it is just this grid of numbers:")
print(tiny_image)
print()
print(f"Image shape: {tiny_image.shape}") # (4, 4) — 4 rows, 4 columns
print(f"Minimum pixel value: {tiny_image.min()}") # 0 (black)
print(f"Maximum pixel value: {tiny_image.max()}") # 255 (white)Why This Matters for Computer Vision
- Every image operation in CV is ultimately a mathematical operation on these numbers
- Brightness adjustment = adding or subtracting a value from every pixel number
- Blur = averaging nearby pixel numbers together
- Edge detection = finding where pixel numbers change rapidly
- Object detection = a model learns which patterns of numbers correspond to objects
- Understanding images as numbers is the mental model behind all CV algorithms
Key Takeaways
- A human sees a cat in a photo.
- Every image operation in CV is ultimately a mathematical operation on these numbers
- Brightness adjustment = adding or subtracting a value from every pixel number
- Blur = averaging nearby pixel numbers together