Fisheye distortion¶
| Fact | Value |
|---|---|
| Also called | Fisheye lens, Bulge |
| Status | Implemented and tested |
| Family | Artistic and geometric effects |
| Engine | Browser |
| Type | Linear, geometric, fisheye radial mapping |
| Output | Image |
| Operator shown as | algorithm (exact) |
| Support radius | global |
| Code | web/src/core/filters/artistic/distort.ts, fisheyeFilter |
| Operator code | web/src/core/filters/artistic/distort.ts, fisheyeSource |
| Channels | RGB |
Overview¶
The fisheye distortion bends the image as a fisheye lens would. The center grows and the edges are pressed together, while the corners stay in place. It redraws the image as an equidistant fisheye with the same field of view.
How it works¶
- Measure each output pixel's distance from the center.
- Read the source from closer to the center, by the ratio of the two lens projections.
- Interpolate the source bilinearly.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(r\): The distance of an output pixel from the image center, as a share of half the diagonal
- \(r_s\): The distance of the source position it reads, in the same unit
- \(\theta_m\): Half the field of view
An equidistant fisheye lens maps the angle theta of a ray to an image radius proportional to theta, one of the projections that Kannala and Brandt describe. A normal, rectilinear lens maps it to a radius proportional to tan theta. The filter treats the image as a rectilinear view with the same diagonal field and redraws it as an equidistant fisheye. A pixel at radius r shows the ray at angle r theta_m, which the source shows at tan(r theta_m) / tan(theta_m). Near the center r_s is less than r, so the center is enlarged, while the corners stay where they are. Each output pixel reads the source at the mapped position with bilinear interpolation, the inverse mapping of Gonzalez and Woods, so no holes appear.
A rectilinear lens, the usual kind, keeps straight lines straight: a ray at angle theta lands at a radius proportional to tan theta. An equidistant fisheye lands it at a radius proportional to theta itself. For small angles the two agree, but toward the edge tan theta grows much faster. Redrawing a rectilinear image in the fisheye model therefore enlarges the center relative to the edges.
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 r from the center.
- Compute the source distance tan(r theta_m) / tan(theta_m), in the same direction.
- Read the source there with bilinear interpolation, using the border mode outside the image.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Field of view fov |
120 | 10 to 170 deg | The diagonal field of view of the fisheye, in degrees. |
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¶
fisheyeFilter 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¶
| r | 0 | 0.2 | 0.4 | 0.6 | 0.8 | 1 |
|---|---|---|---|---|---|---|
| r_s, 90 degrees | 0 | 0.158 | 0.325 | 0.510 | 0.727 | 1 |
| r_s, 150 degrees | 0 | 0.072 | 0.155 | 0.268 | 0.464 | 1 |
The source distance that an output pixel at distance r reads, both as shares of half the diagonal. The center reads from closer in, so it is enlarged, and the corner at r = 1 stays. A wider field enlarges the center more.
Complexity¶
- Time: \(O(N)\)
- Memory: \(O(N)\)
N is the number of pixels. Each output pixel reads four source pixels.
Artifacts and limitations¶
Limitations
- Real fisheye photos have a circular or very wide field. This filter keeps the frame.
Artifacts
- Soft corners, where the source is pressed together.
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 the corners stay and that the center reads from closer in.
web/src/core/filters/filters.test.tsweb/src/core/filters/run.test.tsweb/src/core/filters/artistic/artistic.test.ts
References¶
- Kannala, J. and Brandt, S. S. A generic camera model and calibration method for conventional, wide-angle, and fish-eye lenses. IEEE Transactions on Pattern Analysis and Machine Intelligence 28(8), 1335 to 1340, 2006. DOI 10.1109/TPAMI.2006.153.
- Gonzalez, R. C. and Woods, R. E. Digital Image Processing, 4th edition. Pearson, 2018. Chapter 2, geometric transformations and image interpolation.