72 min total

Computer Vision & OpenCV

Edge detection

Edge detection

An edge is a location where image intensity changes rapidly.

Edge detection: technique that identifies sudden changes in an image, marks border of objects

Edges arise due to:

  • Changes in surface orientation
  • difference in object distances
  • different textured material
  • shadows or lighting changes
An edge and its intensity derivative

Types of edges

Step, ramp, and roof edges

Why do edge detection:

  • helps in object recognition
  • Helps analyze geometry of an object
  • extracts useful features from images
Image scanline, intensity, and derivatives with and without noise

Smoothing: Smoothing reduces noise but blurs edges. smoothing before differentiation: apply a smoothing function (e.g. Gaussian filter) before computing derivatives.

Why Smoothing?

  • Noise impacts edge detection by making pixels appear different from their neighbors.
  • 'difference' filters (Sobel, Prewitt, Laplacian) respond strongly to noise.
  • Filters mistakenly detects false edges due to noise.

Different kernel sizes affect sharpness. 1pixel→minimal smoothing, 3pixel→moderate smoothing, 7pixel→strong smoothing but edges become less precise.

Evaluating edge detection

TP: correctly detected edges, FP: incorrectly detected edges, FN: missed edges, GT: Actual edges present in image, Results of Method(RM): Edges detected by the algorithm.

Design criteria for edge detection:

  • good detection - find all real edges while ignoring noise and artifacts
  • good localization - detected edges should be as close as possible to actual edges
  • minimal false detections - should not produce multiple responses for a single edge.

Challenges to edge detection

Edge detection errors: noise, localization, and duplicate responses

Edges are located at points where intensity changes significantly

Poor robustness to noise: Detects false edges.

Poor localization: Edges are not detected accurately.

Too many responses: Multiple detections for the same edge.

Derivative of images

Derivative: represents rate of change of function

Finite differences and gradients

ApproximationUnit-step expressionMask
Forward differencef(x+1) − f(x)[−1, 1]
Backward differencef(x) − f(x−1)[−1, 1], shifted
Central difference(f(x+1) − f(x−1))/2[−1, 0, 1]/2

Two-dimensional derivative masks

These masks combine a central difference in one direction with accumulation in the perpendicular direction. Dividing the 1D central difference by two estimates the derivative per unit spacing. Unnormalized masks instead retain a scale factor. Reversing a mask changes the derivative sign.

Thresholding: technique used in image processing to convert a grayscale image into binary image by selecting a threshold value.

The Prewitt detector estimates horizontal and vertical derivatives, computes gradient magnitude, and uses a threshold to mark edges.

The Sobel operator gives more weight to central pixels in the perpendicular smoothing direction.

Worked Sobel example

Using the Sobel masks with valid cross-correlation (no padding), the responses are:

The nonzero gradients point horizontally. A magnitude threshold of 30 produces the following binary edge map:

Sobel calculation at one pixel

Repeating the same calculation over every valid patch gives the response matrices above. The notebook’s nonzero vertical response and approximately 44.72 magnitude were arithmetic errors: every input row is identical. With threshold 30, a response of 40 is an edge and a response of 0 is not.