Posterize¶
| Fact | Value |
|---|---|
| Also called | Posterization, Quantize levels |
| Status | Implemented and tested |
| Family | Artistic and geometric effects |
| Engine | Browser |
| Type | Nonlinear, point, quantization transfer |
| Output | Image |
| Operator shown as | point-transfer (exact) |
| Support radius | 0 |
| Code | web/src/core/filters/enhancement/point-ops.ts, posterizeFilter |
| Operator code | web/src/core/filters/enhancement/point-ops.ts, posterizeTransfer |
| Channels | RGB, Brightness only |
Overview¶
Posterize keeps only a few levels per channel, so smooth shading turns into flat bands of color. It gives a poster-like look, and it shows what happens when an image has too few intensity levels.
How it works¶
- Cut the range 0 to 255 into equal bins, one per level.
- Find the bin of each value.
- Replace the value with the level of its bin. The levels run evenly from 0 to 255.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(I\): Input value from 0 to 255
- \(n\): The number of levels
The range 0 to 255 is cut into n bins of equal width 256 / n. Each bin maps to one of n levels spread evenly from 0 to 255, so black and white stay. This bin rule is PixelNexus's own. Programs differ here. Pillow's ImageOps.posterize keeps the top bits of each value instead, and others round to the nearest level. Gonzalez and Woods show the same effect when they reduce the number of intensity levels.
Posterizing is uniform quantization. With n levels, neighboring values in one bin become equal, and the jump between bins is 255 / (n - 1). In smooth areas these jumps show as false contours, lines that are not in the scene.
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 of bins and levels.
- Look up every pixel value in the table.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Levels levels |
4 | 2 to 64 | How many output levels each channel keeps. |
Channels channelScope |
RGB | RGB, Brightness only | Which part of the color image the filter changes. |
Implementation¶
posterizeFilter in web/src/core/filters/enhancement/point-ops.ts uses posterizeTransfer. 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 | 63 | 64 | 127 | 128 | 191 | 192 | 255 |
|---|---|---|---|---|---|---|---|---|
| 4 levels | 0 | 0 | 85 | 85 | 170 | 170 | 255 | 255 |
| Pixel | 0 | 0 | 85 | 85 | 170 | 170 | 255 | 255 |
With 4 levels, the bins are 64 values wide: 0 to 63, 64 to 127, 128 to 191 and 192 to 255. They map to 0, 85, 170 and 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 bins have fixed edges, so the bands do not follow the image content.
Artifacts
- False contours, visible steps in smooth gradients.
Tests¶
The reference writes the same curve with NumPy and applies it to the random test plane. The cases cover 2, 3, 4, 7 and 64 levels.
References¶
- Gonzalez, R. C. and Woods, R. E. Digital Image Processing, 4th edition. Pearson, 2018. Chapter 2, intensity resolution.
- Pillow documentation, the ImageOps module. https://pillow.readthedocs.io/en/stable/reference/ImageOps.html