Skip to content

Steerable filters

Fact Value
Also called Steerable Gaussian derivatives, Oriented derivative of Gaussian
Status Implemented and tested
Family Linear spatial filters
Engine Browser
Type Linear, spatial, steered derivative of Gaussian
Output Image
Operator shown as dynamic-kernel (exact)
Support radius floor(4 sigma + 0.5)
Code web/src/core/filters/linear/steerable.ts, steerableFilter
Operator code web/src/core/filters/linear/steerable.ts, steerableBasis
Channels Brightness only, RGB

Overview

Steerable filters turn a derivative of a Gaussian to any angle by mixing a few fixed basis filters. The first derivative needs two basis filters and responds to edges. The second needs three and responds to thin lines and ridges. Besides the response at one angle, the filter can give the strongest response over all angles and the angle where it is reached, both in closed form.

Four panels: a Siemens star, the first derivative steered to 0 and to 45 degrees, each bright and dark where spokes cross its direction, and the strongest second derivative, which outlines every spoke. Four panels: a Siemens star, the first derivative steered to 0 and to 45 degrees, each bright and dark where spokes cross its direction, and the strongest second derivative, which outlines every spoke.
Steerable derivatives of a Gaussian on a Siemens star. The first derivative at 0 and 45 degrees responds to spokes that cross those directions. The strongest second derivative responds to every spoke edge at once.

How it works

  1. Filter the image with the derivatives of a Gaussian along x and y: two for the first derivative, three for the second.
  2. For one angle, add the basis responses with weights built from the cosine and sine of the angle.
  3. For the strongest response and its angle, solve for the best angle directly.

Mathematical foundation

\[ D_{\theta}^{(1)} = \cos\theta\, G_x - \sin\theta\, G_y,\qquad D_{\theta}^{(2)} = \cos^2\theta\, G_{xx} - 2\cos\theta\sin\theta\, G_{xy} + \sin^2\theta\, G_{yy} \]

The formula shows the default parameter values.

where

  • \(\theta\): The angle
  • \(G_x, G_y\): First derivatives of the Gaussian along x and y
  • \(G_{xx}, G_{xy}, G_{yy}\): Second derivatives of the Gaussian

G_x, G_y, G_xx, G_xy and G_yy are the responses to the derivatives of a Gaussian, built as in scipy.ndimage.gaussian_filter. The y axis points down, so the direction (cos theta, -sin theta) turns counterclockwise on screen. The basis for the second derivative spans the same filters as the three rotated copies of Freeman and Adelson. The strongest output is the gradient magnitude for the first derivative, and the Hessian eigenvalue with the largest size for the second. The angle output is where that maximum is reached. It lies above -180 and up to 180 degrees for the first derivative, and from 0 up to 180 for the second. Where the gradient or the spread of the eigenvalues is below 1e-6, the angle is undefined and set to 0.

Freeman and Adelson called a filter steerable when a few fixed basis filters can make every rotated copy of it. Derivatives of a Gaussian are steerable. The first derivative in direction theta is cos theta times the x derivative, plus sin theta times the derivative in the up direction. The second derivative needs three basis filters. Freeman and Adelson used three rotated copies, at 0, 60 and 120 degrees. This filter uses G_xx, G_xy and G_yy, which span the same filters and are separable. For the first derivative, the strongest response is the gradient magnitude. For the second, it is the Hessian eigenvalue with the largest size, and its angle is the direction of that eigenvector.

Kernel or operator

The Inspector shows the two or three basis kernels with their separable factors, and the weight of each one at the current angle.

Algorithm

  1. Correlate the image with the two or three separable basis kernels.
  2. For the steered output, mix the basis responses with the weights for the angle.
  3. For the strongest output and its angle, find the maximum over all angles in closed form.

Parameters

Parameter Default Values Meaning
Sigma sigma 2 0.5 to 10 px The size of the Gaussian. The kernels end at 4 sigma.
Derivative order First derivative (edges) First derivative (edges), Second derivative (lines) Which derivative of the Gaussian to steer.
Angle angle 0 0 to 360 deg The direction of the derivative. 0 points along x. Angles turn counterclockwise.
Output output Steered to the angle Steered to the angle, Strongest over all angles, Angle of the strongest response The response at the chosen angle, the largest response over all angles, or the angle where it is reached.
Output mapping outputMapping Stretch to full range Absolute value, Offset by 128, Stretch to full range, Clip to 0 to 255 How signed results, such as gradients, become 8-bit pixel values.
Border mode border Reflect 101 (default) Reflect 101 (default), Reflect, Replicate, Constant (zero), Wrap How pixels outside the image are filled when the window reaches past the edge.
Channels channelScope Brightness only RGB, Brightness only Which part of the color image the filter changes.

Implementation

steerableBasis in web/src/core/filters/linear/steerable.ts correlates the plane with separable derivative-of-Gaussian kernels, built as in scipy.ndimage.gaussian_filter and cut at 4 sigma. steeringWeights gives the weights for an angle. The angle output pins the ends of its range, so a zero that rounds to a tiny negative or positive value gives one answer. It is 0 where the response does not depend on the angle. The filter runs in the browser engine, in Web Workers, through the shared filter framework in web/src/core/filters/run.ts, which handles the border mode, the channel scope, alpha and the output mapping. By default it works on luma.

Worked example

Output at the center Value
Steered to 0 degrees, equal to G_x 9.9993
Steered to 90 degrees, equal to -G_y -3.9997
cos 30 x (0 degrees) + sin 30 x (90 degrees) 6.6598
Steered to 30 degrees, from the filter 6.6598
Strongest 10.7696
Angle of the strongest -21.80

A 9 x 9 ramp with the value 10 x + 4 y, sigma 1 and the first derivative. The brightness rises by 10 per pixel along x and by 4 per pixel down, so G_x is close to 10 and G_y close to 4. They come out slightly low, because the Gaussian is cut at 4 sigma. The direction at 90 degrees points up, so that output is -G_y. Mixing the outputs at 0 and 90 degrees with cos 30 and sin 30 gives the output at 30 degrees, which is the steering rule. The strongest response is the length of (G_x, G_y), and its angle, atan2(-G_y, G_x), points toward the brightest side, down and to the right.

Complexity

  • Time: \(O(N r)\)
  • Memory: \(O(N)\)

N is the number of pixels per channel and r the kernel radius. Each basis kernel is separable.

Artifacts and limitations

Limitations

  • The derivative of a Gaussian is broad in direction, so it separates nearby angles poorly.
  • The angle output means little in flat areas.

Artifacts

  • Thick responses for large sigma.

Tests

The reference runs scipy.ndimage.gaussian_filter with derivative orders and steers with NumPy, with the same rules for the angle output. Before the cases are written, the script checks a tilted ramp. The steered first derivative equals its slope along the ramp and 0 across it, and the angle output finds the direction of the ramp. The cases cover both derivatives and all three outputs for all five border modes.

References