Computer Vision - Image Gradient

Sobel Operator, Signed Distance Field

Posted by Rico's Nerd Cluster on January 10, 2021

Image gradients capture the rate of intensity change in an image and are fundamental for detecting edges.

Sobel Operator

The Sobel operator is a popular edge detection filter that computes image gradients by combining smoothing with differentiation. It approximates the gradient of an image’s intensity using two 3×3 kernels—one for the horizontal (X) direction and one for the vertical (Y) direction—derived from a smoothing filter (typically [1, 2, 1]) and a differentiation filter (typically [-1, 0, 1]).

  • X Direction: the Sobel kernel for the X derivative is formed by applying a smoothing filter along the vertical axis and a differentiation filter along the horizontal axis. With a normalization factor of 1/8, it is given by:
1
2
3
[ -1,  0,  1 ]
[ -2,  0,  2 ] * 1/8
[ -1,  0,  1 ]
  • Y Direction: for the Y derivative, the kernel uses the same concept, but with the roles reversed (note that the sign convention for the Y axis might be inverted relative to X):

[ 1, 2, 1 ] [ 0, 0, 0 ] * 1/8 [ -1, -2, -1 ]

Application:

  • Convolution: the original image A is convolved with these kernels (using correlation or, equivalently, convolution with a flipped kernel) to compute the horizontal and vertical gradients:
1
2
Ax=Gx∗A
Ay=Gy∗A

Gradient Magnitude and Direction: The overall gradient magnitude GG is computed as:

\[\begin{gather*} \begin{aligned} & G = \sqrt{A_x^2 + A_y^2} \end{aligned} \end{gather*}\]

The gradient direction is determined by:

\[\begin{gather*} \begin{aligned} & \theta = atan2(A_y, A_x) \end{aligned} \end{gather*}\]

Noise Reduction

In the real world, noise often produces many high gradients that do not correspond to actual edges. To combat this, image processing pipelines typically apply a smoothing filter before computing gradients. This smoothing is distinct from the implicit smoothing in operators like Sobel.

The key idea is based on the associative property of differentiation:

Those noise would yield:

Therefore we need to smooth the pic first: (take x direction for example) (so this is different smoothing than sobel operator) del(h * f)/del(x) = del(h)/del(x) * f

  • smoothing function h, and h’ are, which will save us from a whole differentiation cycle.
  • This is because differentiation allows associativity, and associaitivity allows us to get direvative of the filter.

How do we know where there’s a peak? Use the second derivative. We can identify extremas

Second Order Derivative

To visualize the first order derivative of the fitlers:

Visualization of First Order Derivative of Smoothing Filters

The bigger the smoothing filter, the less noise will be incorporated

Smoothing Filter

Signed Distance Field

Signed Distance Field of a cat:

Source

With signed-distance-field, we can create a “fake” 3D effect on the cat:

Source

A Signed Distance Field (SDF) represents surfaces implicitly by storing the shortest distance to the nearest surface at each point in space. While SDFs enable smooth surface reconstruction, they are not commonly used in industry due to computational complexity.

Instead, Surfel-based methods are more practical, representing surfaces as discrete surface elements (surfels)—small patches that approximate local geometry.

Here is a video of a surfel based method

Video: Real-time Scalable Dense Surfel Mapping (2018)