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.
How it works¶
- Measure each output pixel's distance from the center.
- Move that distance by a sine of the distance.
- Read the source at the moved position, at the same angle.
Mathematical foundation¶
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¶
- For each output pixel, find its distance from the center.
- Move the distance by the sine of the distance.
- 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.
web/src/core/filters/filters.test.tsweb/src/core/filters/run.test.tsweb/src/core/filters/artistic/artistic.test.ts
References¶
- Gonzalez, R. C. and Woods, R. E. Digital Image Processing, 4th edition. Pearson, 2018. Chapter 2, geometric transformations and image interpolation.