Part II: Classical Computer Vision
Chapter 9: Edges, Lines & Curves

Edges, Lines & Curves

"My job is to look at two million pixels and report back with a handful of lines. Compression is easy; the hard part is deciding which 1,999,500 pixels were beside the point."

A Ruthlessly Selective Edge Detector
Big Picture

This chapter is where the book stops processing images and starts understanding them: it turns arrays of pixel intensities into geometric structure, the edges, lines, and curves that describe what a scene contains rather than what its pixels measure. The derivative filters of Chapter 3 gave us gradient maps; here the Canny detector distills them into clean one-pixel-wide contours, the Hough transform groups those contours into lines and circles by letting pixels vote, and robust fitting sharpens the votes into precise parametric curves that survive outliers. The chapter ends by assembling every piece into a working lane-marking detector, the same architecture that shipped in early driver-assistance systems and still runs as a fallback in some of them.

Chapter Overview

Part I treated an image as a signal to be improved: denoised in Chapter 7, sharpened and filtered in Chapter 3, warped in Chapter 5. Whatever we did, the output was always another image. This chapter changes the type signature. The output of an edge detector is not an image in any useful sense; it is a claim about the world: "here, the scene changes." The output of a line detector is more abstract still: four numbers that summarize ten thousand pixels. This progression, from dense arrays toward compact symbolic descriptions, is the central project of classical computer vision, and edges are its first step because nearly every meaningful boundary in a scene (an object's silhouette, a road marking, the corner of a building) announces itself as a rapid change in intensity.

The chapter follows a deliberate arc from evidence to structure. Section 9.1 revisits the image gradient with new eyes: not as a filter output but as a measuring instrument, and confronts the gap between a gradient map (a number at every pixel) and an edge map (a decision at every pixel). Section 9.2 closes that gap with the Canny detector, a four-stage pipeline from 1986 that remains the most-used edge detector on the planet; we build every stage from scratch, then compress the whole thing into one OpenCV call. Section 9.3 asks what to do with edge pixels once we have them, and answers with one of the field's most elegant ideas: the Hough transform, which detects lines and circles by letting every edge pixel vote for every shape that could pass through it. Section 9.4 trades the Hough transform's robustness for precision, fitting parametric curves by least squares, then rescuing least squares from its fatal sensitivity to outliers with M-estimators and RANSAC, an algorithm so durable that it will reappear in Chapter 10, Chapter 13, and Chapter 14.

Section 9.5 is the payoff: a complete, working lane-marking detection pipeline that thresholds gradients and colors, warps the road into a bird's-eye view using the homography machinery of Chapter 5, gathers lane pixels with a sliding-window search, fits robust polynomials, and reports lane curvature in meters. It is a genuinely deployed architecture, and it is also a teaching instrument: every stage exercises a section of this chapter, and every failure mode (shadows, worn paint, rain) illustrates exactly why the deep learning methods of Part III were invented.

One more reason to take this chapter seriously, even in 2026: edges refuse to retire. The first convolutional layer of virtually every trained CNN rediscovers oriented edge detectors on its own, as we will see in Chapter 19. And at the far end of the book, Canny edge maps return as one of the most popular conditioning signals for controllable image generation: ControlNet and its successors steer diffusion models with precisely the one-pixel-wide contours this chapter teaches you to compute, a story told in Chapter 35. The gradient-to-geometry pipeline you learn here is not a historical exhibit; it is a load-bearing wall of the modern stack.

Prerequisites

This chapter leans directly on the derivative filters (Sobel, Scharr, Laplacian) of Chapter 3: Spatial Filtering & Convolution, especially Section 3.4; if gradient magnitude and orientation feel hazy, reread that section first. Thresholding and histogram reasoning from Chapter 2: Point Operations, Histograms & Thresholding appear in every section. The lane-detection capstone in Section 9.5 uses the perspective transform from Chapter 5: Geometric Transformations & Image Warping and benefits from the binary-image cleanup operations of Chapter 6: Morphology, Binary Images & Shape. As always, fluency with NumPy arrays from Chapter 0 is assumed, and the noise models of Chapter 7 explain why every detector in this chapter begins by smoothing.

Chapter Roadmap

What's Next?

Edges describe where the image changes, but they are anonymous: one stretch of contour looks much like another, which is why this chapter could group them only with strong geometric priors (lines, circles, polynomials). Chapter 10: Keypoints, Descriptors & Matching takes the complementary path: instead of long anonymous curves, it finds compact distinctive points (corners and blobs) and equips each with a fingerprint descriptor so it can be recognized again in a different photograph. That single capability, finding the same point in two images, unlocks panorama stitching, camera calibration, stereo depth, and ultimately the 3D reconstruction pipelines of Chapters 12 through 14. The RANSAC estimator you meet in Section 9.4 travels there with you; it is the standard tool for separating correct matches from false ones.

Bibliography & Further Reading

Foundational Papers

Canny, J. "A Computational Approach to Edge Detection." IEEE TPAMI (1986). doi:10.1109/TPAMI.1986.4767851
The paper behind Section 9.2: edge detection posed as an optimization over detection, localization, and single response, solved with the pipeline that still bears Canny's name forty years later.
Duda, R. and Hart, P. "Use of the Hough Transformation to Detect Lines and Curves in Pictures." Communications of the ACM (1972). doi:10.1145/361237.361242
Introduced the polar (rho, theta) line parameterization taught in Section 9.3, turning Hough's bubble-chamber patent into the algorithm every vision library implements.
Fischler, M. and Bolles, R. "Random Sample Consensus: A Paradigm for Model Fitting with Applications to Image Analysis and Automated Cartography." Communications of the ACM (1981). doi:10.1145/358669.358692
RANSAC, the robust estimator of Section 9.4 and arguably the most reused algorithm in geometric vision; the original paper is short and worth reading in full.
Matas, J., Galambos, C., and Kittler, J. "Robust Detection of Lines Using the Progressive Probabilistic Hough Transform." Computer Vision and Image Understanding (2000). doi:10.1006/cviu.1999.0831
The algorithm inside OpenCV's HoughLinesP: random sampling plus on-the-fly segment extraction, the practical variant recommended throughout Sections 9.3 and 9.5.
Ballard, D. H. "Generalizing the Hough Transform to Detect Arbitrary Shapes." Pattern Recognition (1981). doi:10.1016/0031-3203(81)90009-1
Voting extended from lines and circles to any template shape, mentioned in Section 9.3; the conceptual ancestor of implicit-shape-model detection.
Fitzgibbon, A., Pilu, M., and Fisher, R. "Direct Least Square Fitting of Ellipses." IEEE TPAMI (1999). doi:10.1109/34.765658
The closed-form ellipse fit behind OpenCV's fitEllipse, used in Section 9.4; a model of how a clever constraint turns a hard problem into an eigenvalue problem.
von Gioi, R. G., Jakubowicz, J., Morel, J.-M., and Randall, G. "LSD: a Line Segment Detector." Image Processing On Line (2012). ipol.im/pub/art/2012/gjmr-lsd
The strongest classical alternative to Hough line detection: region-growing on gradient orientations with a false-detection control, with reference code and an online demo.

Recent Research (2023-2026)

Ye, Y. et al. "DiffusionEdge: Diffusion Probabilistic Model for Crisp Edge Detection." AAAI (2024). arXiv:2401.02032
A diffusion model that generates single-pixel-wide edge maps directly, sidestepping the thick-edge problem that Sections 9.1 and 9.2 solve with non-maximum suppression.
Cetinkaya, B., Kalkan, S., and Akbas, E. "RankED: Addressing Imbalance and Uncertainty in Edge Detection Using Ranking-based Losses." CVPR (2024). arXiv:2403.01795
Modern learned edge detection that confronts the same two demons Canny named in 1986: most pixels are not edges, and annotators disagree about the rest.
Pautrat, R., Barath, D., Larsson, V., Oswald, M., and Pollefeys, M. "DeepLSD: Line Segment Detection and Refinement with Deep Image Gradients." CVPR (2023). arXiv:2212.07766
A hybrid that learns a gradient-like field with a CNN and then runs classical line extraction on top of it: the clearest evidence that the classical machinery of Section 9.3 still earns its keep.
Kluger, F. and Rosenhahn, B. "PARSAC: Accelerating Robust Multi-Model Fitting with Parallel Sample Consensus." AAAI (2024). arXiv:2401.14919
RANSAC modernized: a network proposes which points belong together so that many models (several lines, several planes) can be fit in parallel; context for Section 9.4's frontier discussion.
Honda, H. and Uchida, Y. "CLRerNet: Improving Confidence of Lane Detection with LaneIoU." WACV (2024). arXiv:2305.08366
A strong 2024 learned lane detector and the natural benchmark contrast for Section 9.5's classical pipeline; note how much of its evaluation vocabulary (curvature, lateral offset) the classical pipeline defined.
Zhang, L., Rao, A., and Agrawala, M. "Adding Conditional Control to Text-to-Image Diffusion Models." ICCV (2023). arXiv:2302.05543
ControlNet: the paper that made Canny edge maps a conditioning signal for image generation and gave this chapter's output a second career, previewed in Section 9.2 and developed in Chapter 35.

Books

Szeliski, R. Computer Vision: Algorithms and Applications, 2nd edition (2022). szeliski.org/Book
Chapter 7 of Szeliski covers edges, lines, and fitting with full mathematical depth and excellent historical notes; free online and the standard reference.

Tools & Libraries

OpenCV. "Canny Edge Detection" tutorial. docs.opencv.org
The official OpenCV 4.x walkthrough of cv2.Canny, including the aperture and L2-gradient flags tuned in Section 9.2.
OpenCV. "Hough Line Transform" tutorial. docs.opencv.org
Documentation for HoughLines and HoughLinesP as used in Sections 9.3 and 9.5, with the accumulator semantics spelled out.
scikit-image. "Straight line Hough transform" example gallery. scikit-image.org
A readable pure-Python Hough implementation with accumulator visualizations that complement Figure 9.3.1; also covers the probabilistic variant.

Datasets & Benchmarks

Berkeley Segmentation Dataset and Benchmark (BSDS500). eecs.berkeley.edu
The standard benchmark for boundary detection: 500 images with multiple human annotations, the dataset on which every learned edge detector in the Recent Research list reports results.
CULane: a large-scale lane detection benchmark. xingangpan.github.io/projects/CULane
133,000 frames of urban and highway driving with lane annotations, including the shadow, glare, and no-line categories that stress-test Section 9.5's pipeline.