Level 1: Image Processing¶
Level 1 ยท Overview ยท โฑ๏ธ ~4โ5 weeks at about an hour a day ยท Prerequisites: Level 0: Images and tools, especially Images as arrays and Working with images and video
Level 1 teaches you to transform images: to change their brightness and contrast, filter out noise, find edges, analyze their frequencies, turn masks into countable objects, and warp them into new geometries. These operations are the foundation of every vision system. Classical pipelines are built from them directly, and deep learning uses them everywhere: as preprocessing and augmentation, inside the layers themselves (a convolutional layer is a filter bank), and as the vocabulary for understanding what a network has learned.
Every important idea is taught three ways: the intuition (with before-and-after pictures), the math (derived, not just stated), and the code (implemented from scratch in NumPy, then checked against OpenCV and scikit-image until the numbers agree).
What this level covers¶
Point operations change each pixel on its own: brightness, contrast, gamma, histogram equalization, and thresholding, including Otsu's method derived from first principles. Filtering lets each pixel see its neighbors: convolution and correlation (and the bug that comes from confusing them), Gaussian, median, and bilateral filters, sharpening, and noise. Edges are where images change: gradients, the Laplacian, and the Canny detector built step by step. The frequency domain shows images as sums of waves, which explains blurring, sharpening, aliasing, and image pyramids in one framework. Morphology and segmentation turn masks into objects you can count and measure, and separate objects that touch. Geometric transformations move pixels: rotations, affine maps, and homographies, with the interpolation that makes them look right. The capstone combines all six into a working document scanner.
What you'll be able to do¶
- Diagnose an image from its histogram and fix its contrast with gamma, percentile stretching, equalization, or CLAHE.
- Choose and justify a threshold (fixed, Otsu, adaptive, or HSV) and derive Otsu's criterion from the variance decomposition.
- Implement 2D convolution from scratch, explain correlation versus convolution and border handling, and exploit separability.
- Pick the right denoising filter for each noise model, and measure the result with PSNR.
- Compute image gradients, and build the Canny edge detector from smoothing, non-maximum suppression, and hysteresis.
- Read a Fourier spectrum, verify the convolution theorem, prevent aliasing when downsampling, and build Gaussian and Laplacian pyramids that reconstruct exactly.
- Clean masks with morphology, count objects with connected components, describe shapes with contours, and split touching objects with the distance transform and watershed.
- Write any 2D transform as a \(3 \times 3\) matrix, estimate a homography from point pairs, and warp an image with inverse mapping and bilinear interpolation.
Chapters¶
| # | Chapter | What it covers | Time |
|---|---|---|---|
| 1 | Point operations and histograms | Brightness, contrast, gamma, lookup tables, histograms, equalization via the CDF, CLAHE, Otsu derived, adaptive thresholds, HSV segmentation | ~60 min read + 4โ5 h practice |
| 2 | Convolution and filtering | Correlation vs convolution, kernels, borders, box and Gaussian blur, separability with timings, noise models, median and bilateral filters, unsharp masking | ~65 min read + 4โ5 h practice |
| 3 | Edges and gradients | Finite differences, Sobel and Scharr, gradient magnitude and direction, Laplacian, LoG and DoG, the full Canny pipeline from scratch | ~60 min read + 4โ5 h practice |
| 4 | The frequency domain | Fourier series, the 2D DFT and FFT, magnitude and phase, the convolution theorem, low- and high-pass filters, aliasing and sampling, pyramids | ~65 min read + 4โ5 h practice |
| 5 | Morphology and classical segmentation | Structuring elements, erosion, dilation, opening, closing, top-hat, connected components, contours and shape descriptors, distance transform, watershed, region growing, k-means | ~65 min read + 4โ5 h practice |
| 6 | Geometric transformations | Homogeneous coordinates, the transform hierarchy, homographies and the DLT, forward vs inverse mapping, interpolation, document rectification | ~60 min read + 4โ5 h practice |
The image processing cheat sheet collects every operation in this level, with its OpenCV and scikit-image calls and when to use it.
How to study this level¶
flowchart LR
S["See it:<br/>before and after"] --> D["Derive it:<br/>pen and paper"]
D --> B["Build it:<br/>NumPy from scratch"]
B --> C["Check it:<br/>against OpenCV<br/>and scikit-image"]
C --> P["Break it:<br/>change parameters,<br/>find failure cases"]
P --> S
- Run every code block, and look at every image. Image processing is visual. Change a parameter (a kernel size, a threshold, a \(\sigma\)) and look again. Ten minutes of this teaches more than an hour of reading.
- Implement before you import. Each chapter builds the core algorithm from scratch first. Type it out yourself rather than copying it; then check it against the library with
np.allcloseor a count of differing pixels. When the numbers disagree, find out why: it's usually a border mode, a rounding convention, or a flipped kernel, and those are exactly the details that cause real bugs. - Derive the key results by hand. The CDF as the equalizing transform, Otsu's between-class variance, the central-difference error, the convolution theorem, the bilinear weights, and the DLT equations each fit on half a page. If you can't reproduce a step, reread it, then try again.
- Collect failure cases. For every method, find an image where it fails: a histogram Otsu can't split, noise the bilateral filter preserves, a downsampling that aliases, a watershed that over-segments. Knowing when a tool fails is what separates using it from understanding it.
- Watch the conventions. BGR vs RGB,
uint8overflow,(x, y)vs[row, col],(width, height)sizes in OpenCV, correlation vs convolution, and nonzero-as-foreground masks cause most of the bugs in this level. Each chapter flags them in warning boxes. - Do the exercises before the solutions. They mix derivations, coding, and conceptual questions. The ones that ask you to predict an output are the most valuable: commit to a prediction before you run the code.
You don't need a GPU
Everything in this level runs on a laptop CPU in seconds. The sample images ship with scikit-image, and the rest are synthetic, so there's nothing to download.
Capstone¶
Build a document scanner: find the page, rectify it, and clean it up. You'll take a realistic synthetic phone photo of a page (perspective, uneven lighting, a shadow, blur, noise, and JPEG artifacts) and turn it into a flat, clean, black-and-white A4 scan, using edges, contours, polygon approximation, corner refinement, a homography, morphological illumination correction, and adaptive thresholding. Because the photo is synthetic, you'll know the true corners, so you can measure your accuracy to a fraction of a pixel.
Start with Point operations and histograms.