Log transformation¶
| Fact | Value |
|---|---|
| Also called | Logarithmic transformation, Log transform |
| Status | Implemented and tested |
| Family | Enhancement, illumination and color |
| Engine | Browser |
| Type | Nonlinear, point, logarithmic transfer |
| Output | Image |
| Operator shown as | point-transfer (exact) |
| Support radius | 0 |
| Code | web/src/core/filters/enhancement/point-ops.ts, logTransformFilter |
| Operator code | web/src/core/filters/enhancement/point-ops.ts, logTransfer |
| Channels | RGB, Brightness only |
Overview¶
The log transformation brightens dark values strongly and bright values only a little. It suits images whose values span a huge range, such as a Fourier spectrum, where the few large values would hide everything else.
How it works¶
- Add 1 to the value, so that 0 stays defined.
- Take the natural logarithm.
- Multiply by 255 / ln 256, so that 255 maps to 255.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(I\): Input value from 0 to 255
- \(I_{\text{out}}\): Output value before rounding
- \(c\): The scale that maps 255 to 255
This is the log transformation of Gonzalez and Woods. The constant c makes 255 map to 255, and 0 maps to 0. The curve is steep for small values and flat for large ones. So the dark tones spread out over a wide range and the bright tones are pressed together. Value 1 becomes 31.9 and value 128 becomes 223.5.
The slope of c ln(1 + r) is c / (1 + r). Near 0 the slope is about 46, so small differences in the shadows grow a lot. Near 255 the slope is about 0.18, so the highlights are pressed together. Gonzalez and Woods use the same curve to display Fourier spectra.
Kernel or operator¶
The Inspector draws the transfer curve for the current settings, with the input value on the horizontal axis and the output on the vertical axis. The Point-op curve in the Learn panel draws the same curve with the histograms of the open image before and after.
Algorithm¶
- Build the 256-entry table c ln(1 + v).
- Look up every pixel value in the table.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Channels channelScope |
RGB | RGB, Brightness only | Which part of the color image the filter changes. |
Implementation¶
logTransformFilter in web/src/core/filters/enhancement/point-ops.ts uses logTransfer. The filter is a point filter: the runner builds a table of 256 outputs once and looks up each pixel. Values between two levels, as luma often is, go through the curve directly.
Worked example¶
| Input | 0 | 1 | 8 | 32 | 128 | 255 |
|---|---|---|---|---|---|---|
| c ln(1 + I) | 0 | 31.88 | 101.04 | 160.79 | 223.48 | 255 |
| Pixel | 0 | 32 | 101 | 161 | 223 | 255 |
The levels 0 to 32 spread over the outputs 0 to 161, while the top half, 128 to 255, shares the outputs 223 to 255.
Complexity¶
- Time: \(O(N)\)
- Memory: \(O(1)\)
N is the number of pixels. The 256-entry table makes each pixel a single lookup.
Artifacts and limitations¶
Limitations
- The strength is fixed. Gamma correction gives a curve that can be tuned.
- Bright areas lose contrast.
Artifacts
- Washed-out highlights and a gray, low-contrast look on normal photos.
Tests¶
The reference writes the same curve with NumPy and applies it to the random test plane.
References¶
- Gonzalez, R. C. and Woods, R. E. Digital Image Processing, 4th edition. Pearson, 2018. Chapter 3.