Skip to content

Ripple distortion

Fact Value
Also called Water ripple, Concentric waves
Status Implemented and tested
Family Artistic and geometric effects
Engine Browser
Type Linear, geometric, concentric sine displacement
Output Image
Operator shown as algorithm (exact)
Support radius global
Code web/src/core/filters/artistic/distort.ts, rippleFilter
Operator code web/src/core/filters/artistic/distort.ts, rippleMapping
Channels RGB

Overview

The ripple distortion pushes pixels toward and away from the center in rings, like ripples spreading on water. Its rule is PixelNexus's own.

Two panels: a checkerboard, and the checkerboard with its squares bent into rings around the center. Two panels: a checkerboard, and the checkerboard with its squares bent into rings around the center.
A checkerboard, and the ripple distortion with amplitude 4 and wavelength 24.

How it works

  1. Measure each output pixel's distance from the center.
  2. Move that distance by a sine of the distance.
  3. Read the source at the moved position, at the same angle.

Mathematical foundation

\[ \rho_s = \rho + A \sin\left(\frac{2\pi \rho}{\lambda} + \phi\right), \quad \theta_s = \theta, \qquad A = 4,\ \lambda = 24,\ \phi = 0^{\circ} \]

The formula shows the default parameter values.

where

  • \(\rho, \theta\): The polar coordinates around the image center, in pixels
  • \(A, \lambda, \phi\): The amplitude, the wavelength and the phase

rho and theta are the polar coordinates of an output pixel around the image center, in pixels. It reads the source at the same angle, moved along the radius by a sine of its distance. Rings where the sine rises are stretched and rings where it falls are pressed, which looks like waves on water. This rule is PixelNexus's own. Each output pixel reads the source at the mapped position with bilinear interpolation, the inverse mapping of Gonzalez and Woods, so no holes appear.

The source distance is rho + A sin(2 pi rho / lambda + phase). Where the sine rises, rings are stretched, and where it falls they are pressed. The mapping folds over itself when its slope 1 + (2 pi A / lambda) cos(...) turns negative, which needs an amplitude above lambda / (2 pi).

Kernel or operator

The Inspector shows the mapping with the current settings, then the bilinear read of the source.

Algorithm

  1. For each output pixel, find its distance from the center.
  2. Move the distance by the sine of the distance.
  3. Read the source there with bilinear interpolation, using the border mode outside the image.

Parameters

Parameter Default Values Meaning
Amplitude amplitude 4 0 to 50 px How far pixels move toward or away from the center.
Wavelength wavelength 24 2 to 200 px The distance between two ripple crests.
Phase phase 0 0 to 360 deg The phase of the sine wave.
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.

Implementation

rippleFilter in web/src/core/filters/artistic/distort.ts. It reads the source with sampleBilinear through warpPlane. The filter is global, and it sets movesAlpha, so the runner moves the alpha plane with the same mapping and transparency stays with its colors.

Worked example

Distance rho 0 6 12 18 24 30
Source distance 0 10 12 14 24 34

The distance from the center that a pixel at distance rho reads, with amplitude 4 and wavelength 24. It runs 4 pixels ahead a quarter wave out and 4 pixels behind three quarters out, and matches rho at every half wave.

Complexity

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

N is the number of pixels. Each output pixel reads four source pixels.

Artifacts and limitations

Limitations

  • Rings are centered on the image and do not fade with distance.
  • Amplitudes above about lambda / (2 pi) make the mapping fold over.

Artifacts

  • Folded, repeated rings at large amplitudes and short wavelengths.

Tests

The reference computes the same mapping with NumPy and reads the source with scipy.ndimage.map_coordinates at order 1, an independent bilinear sampler, for several settings and border modes. Unit tests check that amplitude 0 changes nothing.

References

  • Gonzalez, R. C. and Woods, R. E. Digital Image Processing, 4th edition. Pearson, 2018. Chapter 2, geometric transformations and image interpolation.