quantize_uniform — 2D gray op

• Data kinds: image → image

• Call: fullseye.apply(img, "quantize_uniform", a=0.5, b=0.5) (the 2-D model is one image plus two scalar knobs a,b∈[0,1])

quantize_uniform: input → output

*The figure is the actual output on a synthetic 128×128 input. Left: input, right: output. Point clouds are drawn as a top-down scatter (brightness = z), 1-D series as a line plot, volumes as the maximum-intensity projection along z, videos as the middle frame, complex images as magnitude; return values that are not pictures are shown as the values themselves.*

Sweeping knob a (0.1 / 0.5 / 0.9, the other knob at its default):

▸ quantize_uniform: knob a sweep (docs site)

*Knob b does not change the output (measured: identical at 0.1 / 0.5 / 0.9).*

On other images (synthetic scene / photo / coins. Top row: inputs, bottom row: their outputs. Knobs at default):

▸ quantize_uniform: other inputs (docs site)

*The 4th column is a colour (H,W,3) input. This op handles colour without crossing channels (it does not convolve the colour channel as a third spatial axis).*

Usage

Uniform quantizer (rounding). a is the bit count 1 to 8; b is unused.

round(x * (L-1)) / (L-1), L = 2**bits. The step is Δ = 1/(L-1).

The difference from xpil_posterize lies here, and it is not negligible: that op is PIL's implementation and truncates the low bits, so the mean of the output is lower than the input by Δ/2. Measured on a uniformly distributed input, bits=4 gives a mean error of -0.0312 (theory -Δ/2 = -0.03125). The variance is the same Δ²/12 for both, but because of the bias the squared error

truncation: Δ²/12 + (Δ/2)² = Δ²/3 rounding: Δ²/12

differs by a factor of 4. If it is placed in front of a brightness measurement, it must be rounding.

Conditions of use and error (closed form): when the input varies enough relative to the step (the quantization noise can be regarded as uncorrelated with the input), the error is uniformly distributed on [-Δ/2, +Δ/2] with mean 0 and variance Δ²/12. This assumption breaks down in flat regions, where the error correlates with the signal and turns into stripes (banding) — if you want to treat the error as noise, pass it through dither_ordered or dither_floyd_steinberg. Whether steps are visible can be measured with banding_map.

Detailed usage guide

• gallery2d_gray_arith family guide

References (sample data, literature)

• Sample-data catalog (download URLs / licences) — 2-D uses skimage.data (BSD/public domain) plus synthetic images; 3-D lists download URLs for real data sources (Stanford, PDS, …).

• Operator provenance and references — the sources of the research/methods this op family came from.

• The canonical algorithm (author, year) and its uses are named in the family usage guide above.

Try it in Studio

The program below has been verified to run (same input as the figure). In Studio's help this block becomes buttons that load and run it on the spot.

quantize_uniform 0.50 0.50

▸ Load this pipeline  ·  Load & run

Runnable examples (verified samples that actually call this op)

• gallery2d_gray_arith — py -3.11 examples/gallery2d_gray_arith.py

Ops the type connects to (they accept image as input)

identity · gaussian · mean_box · bilateral · unsharp · median · min_filter · max_filter

Same category (gray)

gamma · quantize_lloyd_max · quantization_error · dither_ordered · dither_floyd_steinberg · companding_mu_law · banding_map · invert


*Provenance: ops.py — 2D operator registry. This per-op note is generated by tools/opdocs.py md (do not hand-edit).*

© 2026 Kazufumi Furuse — Fullseye operator documentation. Licensed under Apache-2.0.