Skip to content

Domain transform filter

Fact Value
Also called Domain transform, Edge-aware domain transform, Gastal-Oliveira filter
Status Implemented and tested
Family Nonlinear spatial filters
Engine Science engine
Type Nonlinear, spatial, edge-aware 1-D filtering in a transformed domain
Output Image
Operator shown as algorithm (exact)
Support radius 3 * sigmaSpatial
Code engine/src/pixelnexus_engine/filters/edge_preserving.py, domain_transform
Operator code engine/src/pixelnexus_engine/filters/edge_preserving.py, domain_transform_representation
Packages OpenCV

Overview

The domain transform smooths an image while keeping its edges, after Gastal and Oliveira. It stretches each row and column where the colors change, so pixels on two sides of an edge end up far apart. A fast 1-D filter in that stretched domain then smooths each side on its own. Its cost does not grow with the sigmas, which makes it much faster than a bilateral filter with a large reach. The filter runs in the PixelNexus engine, with OpenCV.

Four panels. A noisy bright disk and gray square on a dark ground. With the defaults, the noise is a little softer and the edges stay sharp. With a color sigma of 40, the result looks almost like the input. With the recursive filter, the noise is a little softer again. Four panels. A noisy bright disk and gray square on a dark ground. With the defaults, the noise is a little softer and the edges stay sharp. With a color sigma of 40, the result looks almost like the input. With the recursive filter, the noise is a little softer again.
A disk and a square with noise of sigma 20. Then the domain transform with the defaults, with a color sigma of 40, and with the recursive filter.

How it works

  1. Stretch every row by the color changes along it.
  2. Filter each row in the stretched domain.
  3. Do the same along every column.
  4. Repeat with smaller sigmas for the given number of passes.

Mathematical foundation

\[ ct(u) = \int_0^u 1 + \frac{\sigma_s}{\sigma_r} \sum_{k=1}^{3} \lvert I_k'(x) \rvert \, dx \]

The formula shows the default parameter values.

where

  • \(ct(u)\): The position of pixel u on the stretched axis
  • \(\sigma_s\): The spatial sigma
  • \(\sigma_r\): The color sigma
  • \(I_k'\): The change of channel k between neighbors

Gastal and Oliveira map each row, or column, to a new axis ct. A step of one pixel adds 1, plus the color change between the two pixels times sigma s over sigma r. So in flat areas the new axis looks like the old one, and at an edge it jumps far. A 1-D filter of sigma s along ct then mixes pixels only when they are close on the new axis, which means close in space and in color. Rows and columns take turns, and each pass uses a smaller sigma so that the passes together smooth with sigma s. Every step is linear in the number of pixels, whatever the sigmas.

The stretch turns edge-aware smoothing into ordinary smoothing along a curved axis. In flat areas the axis is unchanged, so the filter is a plain blur there. Across an edge, the axis jumps by the color change times sigma s over sigma r, so the blur cannot reach across. The passes alternate between rows and columns. Each pass uses a smaller sigma, chosen so that the passes together smooth with sigma s.

Kernel or operator

There is no fixed kernel. The Inspector asks the engine for the stages with the current settings.

Parameters

Parameter Default Values Meaning
Spatial sigma sigmaSpatial 30 1 to 200 px The sigma H of the smoothing in the stretched domain, like the spatial sigma of a bilateral filter. 30 is our choice.
Color sigma sigmaColor 80 1 to 255 levels The sigma r that says how large a color change counts as an edge. 80 is our choice.
Mode mode Normalized convolution Normalized convolution, Interpolated convolution, Recursive filter The 1-D filter of the paper. Normalized convolution averages a box in the stretched domain, interpolated convolution averages the interpolated signal, and the recursive filter is an exponential filter. OpenCV uses normalized convolution.
Passes iterations 3 1 to 10 How many times the rows and columns are filtered, each pass with a smaller sigma. OpenCV uses 3.

Implementation

domain_transform in engine/src/pixelnexus_engine/filters/edge_preserving.py calls cv2.ximgproc.dtFilter on the 8-bit RGB image, guided by itself. The color change between neighbors adds up over the three channels.

Worked example

Spatial sigma Color sigma PSNR (dB)
10 40 23.01
10 80 27.04
10 120 32.08
30 40 23.16
30 80 27.86
30 120 32.79
60 40 23.17
60 80 27.93
60 120 32.90

The image of the figure, with the other defaults. The PSNR compares the result with the image before the noise. The noisy input scores 22.22 dB.

The domain transform is an edge-aware smoother, not a denoiser. Noise of sigma 20 makes color changes as large as weak edges, so at a color sigma of 40 the filter keeps almost all of it. At 120, the noise counts as flat, and the PSNR rises to 32.9 dB. The spatial sigma matters far less.

Complexity

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

N is the number of pixels and K the number of passes. It does not grow with the sigmas.

Artifacts and limitations

Limitations

  • Weak at removing noise, since noise also looks like edges at small color sigmas.
  • Works along rows and columns, so diagonal edges can show faint streaks.

Artifacts

  • Streaks along rows and columns with few passes.

Tests

The result must equal OpenCV's own call. On a clean step, the two sides must stay exactly 60 and 190. The representation must have its three stages.

References

  • Gastal, E. S. L., and Oliveira, M. M. Domain transform for edge-aware image and video processing. ACM Transactions on Graphics 30(4), 2011. DOI 10.1145/2010324.1964964.
  • OpenCV documentation, cv::ximgproc::dtFilter.