quantize_lloyd_max — 2D gray op

• Data kinds: image → image

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

quantize_lloyd_max: 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_lloyd_max: knob a sweep (docs site)

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

▸ quantize_lloyd_max: knob b sweep (docs site)

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

▸ quantize_lloyd_max: 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

Quantization that is optimal for the distribution of the input (Lloyd–Max, 1-D k-means).

a is the number of bits for the level count, 1-8; b is the number of iterations (1-20). Whereas uniform quantization places the steps at equal intervals, this op places the steps finely where pixel values are crowded. Each representative value is the centroid of its interval, and each interval boundary is the midpoint of adjacent representative values — applying these 2 alternately is Lloyd's iteration, and the squared error decreases monotonically (it never increases).

Condition under which it differs from uniform quantization: when the input histogram is skewed. With a uniformly distributed input it coincides with uniform quantization, so the absence of a difference is itself a check of correctness. For images whose pixels concentrate in the shadows (inspection images with many shadows, fluorescence images), the error drops at the same bit count.

Conditions of use: (1) The output is a set of representative values that depend on the input, so the code table differs per image — pixel values cannot be compared directly with another image (for that, use uniform quantization). (2) Empty intervals remain as they are (their representative values do not move). (3) The iteration can fall into a local optimum, but in 1-D, taking the initial values at quantiles makes it stable in practice.

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_lloyd_max 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_uniform · 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.