Core skills · Lesson 7/9

Computer Vision — Teaching Machines to See

35 min 1 exercise 1 quiz

What you'll learn

  • How an image is just numbers to a computer
  • What convolutions detect (edges → shapes → objects)
  • Real applications: faces, self-driving, medical scans
  • You'll process a mini image grid in code

A picture is a spreadsheet of numbers 🖼️

To you, a photo is a beach. To a computer, it's a grid of numbers — each pixel is a brightness value (0 = black, 255 = white). A color image is three such grids: Red, Green, Blue. That's it. Every image AI does is math on these number grids.

A tiny 3×3 grayscale image:
 [ 255, 255, 255 ]      all white row
 [ 0,   0,   0   ]      a black line!
 [ 255, 255, 255 ]      all white row

See that black row? A computer spots it by noticing where numbers suddenly change — that's an edge. This is the key trick of Convolutional Neural Networks (CNNs), the workhorses of computer vision:

  • Early layers slide small filters over the image to detect edges and simple textures.
  • Middle layers combine edges into shapes (a curve, a corner, a circle).
  • Deep layers combine shapes into objects (an eye, then a whole face).

It's the same "simple → complex, layer by layer" idea from the deep learning lesson, applied to pixels.

Real-world uses you touch daily:

  • Face unlock on your phone
  • Self-driving cars spotting pedestrians and lane lines
  • Medical imaging flagging tumors in X-rays, sometimes better than humans
  • OCR turning a photo of text into editable text

The core skills: represent images as arrays (NumPy again), and use CNNs via PyTorch/TensorFlow. Libraries like OpenCV handle everyday image operations.

Exercise 1

Process an image like a computer does. An image is a list of rows (each row a list of pixel brightnesses 0–255). Write invert(image) that returns a negative of the image: each pixel becomes 255 - pixel.

This is a real image operation (color inversion).

Before training: preprocessing and data augmentation 🧹

Raw photos are messy — different sizes, lighting, orientations. Before a CNN ever sees an image, it almost always goes through preprocessing:

  • Resizing every image to the same fixed dimensions (a CNN expects a consistent input shape).
  • Normalizing pixel values from the 0–255 range down to something like 0–1, which helps training converge faster and more stably.
  • Grayscale or channel adjustments depending on the task.

Even more important is data augmentation — artificially creating more training variety by taking each image and generating slightly altered copies: flipped horizontally, rotated a few degrees, cropped, or brightness-shifted. A photo of a cat flipped left-right is still obviously a cat, but to the network it's a "new" example.

Why bother? Because vision models are notorious for overfitting — memorizing quirks of the exact training photos (like always seeing cats photographed indoors) rather than learning the general concept "cat." Augmentation forces the model to focus on the actual object, not incidental details like background, angle, or lighting. It's one of the cheapest, highest-leverage tricks in the entire computer vision toolbox — free extra data from data you already have.

Real-world case study: the ImageNet moment 🔍

For decades, computer vision progressed slowly with hand-crafted rules ("edges look like this, corners look like that"). Then in 2012, a team entered the ImageNet competition — a benchmark of over a million labeled images across 1,000 categories — with a deep CNN called AlexNet. It didn't just win; it beat the second-place entry by a stunning margin, roughly halving the error rate of the best traditional approaches.

The result sent a shockwave through the entire field. Researchers who had spent careers hand-designing feature detectors realized that a deep CNN, given enough data (ImageNet) and enough compute (trained on GPUs, which were a relatively new trick for this at the time), could learn better features automatically than humans could design by hand. Within a couple of years, nearly every serious computer vision system had switched to deep learning.

This single competition result is widely credited as a turning point that kicked off the modern deep learning boom — the same core CNN ideas from this lesson (convolutions detecting edges → shapes → objects) scaled up with more data and more layers. It's a vivid reminder that in AI, sometimes the breakthrough isn't a clever new trick, but simply proving that a simple idea works dramatically better once you have enough data and computing power behind it.

Quick quiz

Question 1 of 5

To a computer, an image is…

Question 2 of 5

What do the early layers of a CNN detect?

Question 3 of 5

How does a computer detect an edge?

Question 4 of 5

Why do we use data augmentation on training images?

Question 5 of 5

What made the 2012 ImageNet result (AlexNet) so significant?

Summary

  • Images are grids of numbers; color = R/G/B grids
  • CNNs detect edges → shapes → objects, layer by layer
  • Powers face unlock, self-driving, medical imaging, OCR
  • Preprocessing (resize, normalize) and data augmentation (flips, rotations) fight overfitting and improve generalization
  • You wrote a real image-inversion function
  • Case study: the 2012 ImageNet/AlexNet result kicked off the modern deep learning boom in vision

Next: MLOps — how AI models actually get deployed and maintained in the real world.

Practice

Reading is not learning until you run something. Pick one.

Open an example in Code Lab