Skip to content

High-pass filter

Fact Value
Status Implemented and tested
Family Linear spatial filters
Engine Browser
Type Linear, spatial, convolution
Output Image
Operator shown as dynamic-kernel (exact)
Support radius floor(3 * sigma + 0.5)
Code web/src/core/filters/linear/high-pass.ts, highPassFilter
Operator code web/src/core/filters/linear/high-pass.ts, boostKernel
Channels Brightness only, RGB

Overview

The high-pass filter keeps only the fine detail of an image. It subtracts a Gaussian blur from the image, so flat areas become 0 and edges remain. The result is signed, so the output mapping turns it into a picture. By default it adds 128, which makes flat areas middle gray.

Three panels: a Siemens star, its high-pass with sigma 1, and with sigma 4. Both results are middle gray in flat areas. Sigma 1 keeps thin lines at the spoke edges, sigma 4 keeps wider bands. Three panels: a Siemens star, its high-pass with sigma 1, and with sigma 4. Both results are middle gray in flat areas. Sigma 1 keeps thin lines at the spoke edges, sigma 4 keeps wider bands.
The high-pass keeps the edges of the spokes and turns flat areas middle gray.

How it works

  1. Make a blurred copy of the image.
  2. Subtract the copy from the image.
  3. Add 128, so the signed detail can be seen as lighter and darker gray.

Mathematical foundation

\[ H(x,y) = I(x,y) - (G_{\sigma} \star I)(x,y), \qquad \sigma = 2 \]

The formula shows the default parameter values.

where

  • \(I\): Input channel value
  • \(H\): High-pass result, signed
  • \(G_{\sigma}\): Normalized Gaussian kernel with radius floor(3 sigma + 0.5)
  • \(\star\): Correlation
  • \(\sigma\): Standard deviation of the Gaussian in pixels

The Gaussian blur keeps the coarse picture. What is left after subtracting it from the image is the fine detail H, a signed value that is 0 in flat areas. The output mapping turns it into a visible image. The default adds 128, so flat areas are middle gray.

The filter is one kernel: a unit impulse minus the Gaussian kernel. Its weights add up to 0, so flat areas give exactly 0. The Gaussian passes low frequencies, so the difference passes the high ones. Its frequency response is close to \(1 - e^{-2\pi^2 \sigma^2 f^2}\) for the frequency \(f\) in cycles per pixel. That is an approximation, because the Gaussian kernel is sampled and cut off at 3 sigma.

Kernel or operator

The kernel for \(\sigma = 0.5\), from the filter code. The weights add up to 0.

\[ H_{\sigma=0.5} = \begin{bmatrix} 0.0000 & 0.0000 & -0.0002 & 0.0000 & 0.0000 \\ 0.0000 & -0.0113 & -0.0837 & -0.0113 & 0.0000 \\ -0.0002 & -0.0837 & 0.3813 & -0.0837 & -0.0002 \\ 0.0000 & -0.0113 & -0.0837 & -0.0113 & 0.0000 \\ 0.0000 & 0.0000 & -0.0002 & 0.0000 & 0.0000 \end{bmatrix} \]

Algorithm

  1. Blur the image with a Gaussian of the given sigma.
  2. Subtract the blur from the image.
  3. Map the signed result to 8 bits with the output mapping. Keep alpha unchanged.

Parameters

Parameter Default Values Meaning
Sigma sigma 2 0.3 to 50 px Standard deviation of the Gaussian low-pass that is subtracted.
Output mapping outputMapping Offset by 128 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

boostPlane in web/src/core/filters/linear/high-pass.ts blurs with the Gaussian filter code and subtracts. The high-boost filter shares this function. The filter works on luma by default, so the result is gray.

Worked example

x 0 1 2 3 4 5 6 7 8
Value I 40 40 40 70 150 200 215 215 215
I - G * I -0.3 -2.1 -13.9 -18 9.9 15.3 7.8 1.1 0.1
Offset by 128 128 126 114 110 138 143 136 129 128

Sigma 1 on a soft edge whose rows are all the same. Far from the edge the detail is 0, so the pixel is 128. The dark side of the edge is negative and the bright side positive.

Complexity

  • Time: \(O(N\,(2r+1))\)
  • Memory: \(O(N)\)

N is the number of pixels per channel and r the Gaussian radius. The blur is separable.

Artifacts and limitations

Limitations

  • The result is not a photo. It is the detail around middle gray.
  • Noise is detail too, and it stays.

Artifacts

  • Halos around large edges, with the width of the blur.

Tests

The test compares the signed result before the output mapping with the image minus scipy.ndimage.gaussian_filter, for two sigmas and three border modes.

References