Edge detection

Select an image:
Select an edge detection method:
The Sobel operator finds edges by convolving the image with a pair of 3x3 kernels designed to detect horizontal and vertical edges.
The horizontal and vertical Sobel kernels are:

  • Each of the kernels calculates the discrete derivative of the image in a given direction; by doing this over a 3x3 neighborhood we also smooth the image, which helps to reduce noise.
    Notice how each kernel highlights a different direction of edges.
  • The two resulting images are then combined to obtain the final edge map by computing the gradient magnitude (square root of the sum of the squares of the horizontal and vertical gradients).
  • Finally, the gradient magnitude can be thresholded to obtain a binary edge map (1-bit image).
The Prewitt operator is similar to the Sobel operator, but uses a different pair of 3x3 kernels:

The Prewitt kernels don't put as much weight on the central pixel as the Sobel kernels, which makes them less sensitive to noise.
  • As for the Sobel kernels, each of the kernels calculates the discrete derivative of the image in a given direction; by doing this over a 3x3 neighborhood we also smooth the image, which helps to reduce noise.
    Notice how each kernel highlights a different direction of edges.
  • The two resulting images are then combined to obtain the final edge map by computing the gradient magnitude (square root of the sum of the squares of the horizontal and vertical gradients).
  • Finally, the gradient magnitude can be thresholded to obtain a binary edge map (1-bit image).
The Laplacian of the Gaussian (LoG) operator is a tool that can be used in edge-detection algorithms (such as the Marr-Hildreth algorithm), based on the second derivative of the image.
Specifically, the Laplacian operator, is the sum of the second derivatives of the image in the x and y directions.

The zero-crossings of this function correspond to the edges in the image.
This can be approximated by this kernel:
  • The LoG operator is very sensitive to noise, so it is usually applied after smoothing the image with a Gaussian filter (hence the name).
  • In practice, the LoG can be calculated in one go, using a kernel such as this (this is smoothing with sigma=1.4).
  • The LoG is anisotropic, meaning that it is sensitive to edges in all directions, an advantage compared to the Sobel and Prewitt kernels
The Canny edge detector is a widely used multi-step algorithm for edge detection.
The steps are:
  1. Smoothing the image with a Gaussian filter to reduce noise.
  2. Finding the intensity gradients of the image.
  3. Suppressing non-maximum pixels (thin the edges).
  4. Double thresholding to find potential edges.
  5. Edge tracking by hysteresis: connecting edges that are above the high threshold and connected to an edge above the low threshold.

The sigma parameter controls the amount of smoothing applied to the image before finding the gradients; try different values to see how the edge detection changes. Can you guess what is the effect of a high vs a low sigma?
The low and high thresholds control the minimum and maximum intensity gradient values that are considered as edges.