companding_mu_law — 2D gray op

• Data kinds: image → image

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

companding_mu_law: 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):

▸ companding_mu_law: knob a sweep (docs site)

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

▸ companding_mu_law: knob b sweep (docs site)

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

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

μ-law companding (compand = compress + expand). a is μ; b is the bit count.

It stretches the shadows with F(x) = ln(1 + mu*x) / ln(1 + mu), then quantizes, and returns via the inverse transform. As a result the steps become fine in the shadows and coarse in the highlights — since both the eye and the imaging system are sensitive to differences in the shadows, the visible degradation is smaller at the same bit count. It is the same principle as telephone speech coding (G.711); for images it amounts to a logarithmic allocation of grey levels.

a gives mu = 1 + 254*a (1-255; a=0 leaves it essentially unchanged), b is the bit count 1-8.

Difference from Lloyd–Max: that op fits the distribution of that image, so the code table changes from image to image. This op uses a fixed curve, so values can be compared as they are with other images and other devices. If the assumption that the distribution is logarithmically skewed holds, it performs similarly; if it does not, Lloyd–Max is better.

Conditions of use (with measurements): when the input is in [0,1] and pixels concentrate near 0. Compared with uniform quantization on synthetic images with an exponential distribution, concentration in the shadows lowers the squared error to 0.57 times (3 bit) and 0.51 times (5 bit). Concentration in the highlights instead makes it worse by 7.7 times (3 bit) and 18 times (5 bit) — an inspection image of dark scratches on a white background is exactly this case, so in that situation pass it through 1 - x before applying it. With very few levels (2 bit) the curve is too strong and it loses to uniform quantization even on a skewed distribution (measured 1.17 times).

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.

companding_mu_law 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 · quantize_lloyd_max · quantization_error · dither_ordered · dither_floyd_steinberg · 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.