DEV Community

Jay
Jay

Posted on Edited on

A main image reads 36.8%, 51.2% or 85.0% full. Same file, same pixels.

The number that circulates for marketplace main images is 85%. White background, product filling most of the frame, nothing else in shot.

I have never seen that rule arrive with a definition of fill, and a fill check is not one measurement. It is a choice between at least four, all defensible, all computable from the same file — and on one ordinary packshot they return 31.9% to 85.0%. That is not a matter of taste. For any packshot whose box is more than 1.176 times longer than it is wide, one of those four readings cannot be satisfied at all, not by a badly framed shot, but by arithmetic.

So I built a packshot whose every property is known by construction and measured the readings against it. Then I did the same for the other half of a compliance check, the part nobody photographs: whether the white field survives the encoder.

Make a file whose answer you know

The hard part of auditing a measurement is that you need a file whose truth you already have. Compositing gives you one for free. Take a matte with an alpha channel, paste it onto a white canvas, and two numbers come out exact without measuring anything:

al = np.asarray(matte).astype(np.float64)[:, :, 3] / 255.0
truth_ink   = al.sum() / (W * H)              # what was composited
truth_box   = (nw * nh) / (W * H)             # the support box
truth_side  = max(nw / W, nh / H)             # the longest side
Enter fullscreen mode Exit fullscreen mode

al.sum() is the coverage: a pixel at alpha 0.5 contributes half. That is what "the product occupies this much of the frame" ought to mean, and it is the number the file is about to lose.

My matte here is 429 × 304, cropped from a 1200 × 800 rembg output, 71.8% ink inside its own box. Placed on a 1200 × 1200 white canvas with the longest side at 85%, the support box comes out 1020 × 723, aspect 1.411, and the composite carries 36.79% ink.

Everything below is measured on that one file.

One 1200 px main image, with the ink tinted blue and the support box outlined: 36.8% of the frame is ink, 51.2% is box, 85.0% is the longest side

Four readings of one 1020 × 723 box

The file is 1200 × 1200 and the product is a mug on a white field. Here is what four different definitions of "fill" say about it, plus the truth that is no longer in the file:

what you measure value
share of pixels that are not exactly 255,255,255 38.43%
share of pixels with min(R,G,B) < 250 31.95%
bounding-box area ÷ frame 51.21%
longest side of the box ÷ frame 85.00%
the alpha coverage that was composited 36.79% — not in the file

The two area readings differ by 60% — 31.95% against 51.21% — and the 85% answer is not an area at all: 85% of the frame's side is 51.2% of its area here, because the box is 1.41 times wider than it is tall.

Note the last row. The true answer existed the moment I composited the file, and flattening to RGB destroyed it. A checker reading a JPEG cannot recover 36.79%. The best it can do is pick a threshold and report what that threshold sees. That is the fourth reading, and it gets its own section below.

The two 85%s, and why one of them cannot be met

Written out, both readings are one line of algebra. For a product whose box is w × h in a square frame of side S, with aspect = max(w,h) / min(w,h) ≥ 1:

  • if 85% means the longest side, then max(w,h) = 0.85·S, so w·h = 0.85²·S²/aspect and the area is 0.85²/aspect
  • if 85% means the area, then w·h = 0.85·S², so max(w,h) = S·sqrt(0.85·aspect)

The second one has a ceiling. sqrt(0.85·aspect) exceeds 1 — the product taller than the frame it is supposed to sit inside — as soon as aspect > 1/0.85 = 1.176.

box aspect 85% as longest side → area 85% as area → longest side
1.00 72.2% 92.2%
1.05 68.8% 94.5%
1.18 61.2% 100.2%
1.41 51.6% 109.5%
2.00 36.1% 130.4%
4.00 18.1% 184.4%

My mug sits at 1.41. Read as an area, "85% full" would require its longest side to be 109.5% of the frame — nine and a half percent wider than the frame itself. The largest box of this shape that fits inside the frame covers 1/1.41 = 70.9%, so the area reading is not a hard framing target here. It is an unreachable one: no zoom, no crop, no amount of white space added or removed gets a 1.41 box to 85% of the area without spilling out of the frame.

Which is worth knowing before you argue with a checker's number. If a tool tells you a 1.41-aspect packshot is "below 85% fill" and it is measuring area, the tool's ceiling for any framing of that product is 70.9%, and the honest answer is that the rule does not apply to the shape. Below aspect 1.176 both readings are satisfiable, and there the area reading is the stricter of the two: at aspect 1.00 it asks for a longest side of 92.2% where the side reading asks for 85%.

The fourth reading: the threshold

Flattened to RGB, the ink is whatever is not white enough. "White enough" needs a cutoff, and the cutoff is the biggest undocumented choice in the whole check.

threshold on min(R,G,B) mask area ratio to the true ink
< 255 38.43% 1.045
< 250 31.95% 0.868
< 245 27.56% 0.749
< 235 23.72% 0.645

A 20-point window of thresholds moves the reported area from 38.4% to 23.7%. So the useful question is not "which threshold" but "what does the error depend on", and there are two candidates worth testing: the size of the product in the frame, and the matte it was cut from.

Measured ink as a ratio to the ink that was composited, against the white threshold, for four mattes at three fills each: the three fills land on one line

Take the second first, because it is the surprising one. I built the same packshot at three fills — 60%, 70% and 85% of the longest side — for each of four segmentation models. Within a single matte, the ratio is the same number at all three fills, to within 0.001:

matte mean alpha of its ink 1 / mean alpha measured ratio at < 255
birefnet-general 0.9558 1.0462 1.0401
bria-rmbg 0.9543 1.0479 1.0448
u2net 0.8978 1.1138 1.1132
silueta 0.8774 1.1397 1.1387

Two things are happening in that table, and the second one deserves its own section. The first is the invariance: scaling a main image does not change the ratio at all. A 4.5% error on a 1200 px file is a 4.5% error on a 2400 px file, because the mask and the coverage scale together. Resizing, in other words, cannot fix this, and neither can downsampling before the check. The error is a property of the edge, not of the pixel count.

The second is the size of the disagreement between models: 1.040 to 1.139 is 9.9 percentage points at the same threshold, on the same file size, for the same product. Two checkers can both implement "product = not white" correctly and still disagree by a tenth of the frame, because their mattes have different mean opacity.

Why it is exactly 1 / mean alpha

At threshold 255 the algebra is forced. A fringe pixel with coverage α over white composites to

out = 255·(1 − α) + p·α
Enter fullscreen mode Exit fullscreen mode

where p is the product's own colour. For any α > 0 and any p < 255, out < 255, so the pixel counts as ink — as a whole pixel. The alpha sum counts it as α. So

mask(255) / coverage = Σ[α > 0] / Σα = 1 / mean(α)
Enter fullscreen mode Exit fullscreen mode

with the mean taken over the pixels the matte calls product. That is the whole error, and it has nothing to do with the image: it is one number read off the matte. The prediction lands within 0.7% on all four models and all three fills.

Look at what the four mattes actually contain, though — measured after the same resize the composite uses, so these are the numbers that are in the 1200 px file:

matte alpha 255 alpha 251–254 alpha < 250 mean alpha
bria-rmbg 0.9% 91.9% 6.9% 0.954
birefnet 4.9% 88.6% 6.3% 0.956
u2net 33.2% 51.3% 15.2% 0.898
silueta 25.7% 54.7% 18.8% 0.877

bria's "solid" interior is 251–254, not 255. Almost none of its product pixels are fully opaque, so under the literal reading of a pure-white requirement, every one of them is technically not white — which is why its mask over-reads by 4.5%, and why "bria's mask is 38% of the frame" and "bria's product covers 36.8%" are both true.

Below 255 the cutoff starts depending on the product colour too, because out < t needs both a small enough α and a dark enough p. That is why the curves fall away rather than staying flat, and why the four models converge as the threshold tightens: from 9.9 points at 255 to 4.5 at 250, 3.6 at 245, 2.5 at 235. A stricter threshold converges on the solid core. It never converges on the truth.

What this means for a fill check

Three practical consequences, all of which follow from the numbers above:

  1. A bare percentage is not comparable across tools. "Your product fills 38%" needs the aspect, the reading, and the threshold before it means anything. Two tools reporting 38% and 32% on the same file may both be internally correct.
  2. The one reading you can defend without a model is the box. Bounding-box area and longest side are computed from pixels and involve no matte, no threshold, no alpha. They overstate the ink — 51.2% against 36.8% here — but they are reproducible, and the 39% gap is a known constant of the shape, not a source of disagreement.
  3. Re-cut the matte, not the image. If a checker's percentage has to move, the matte's mean alpha is the lever, and that is a segmentation decision. Changing the resolution changes nothing, which is worth saying out loud because it is the first thing everyone tries.

The white field under JPEG

The other half of "pure white background" is whether the encoder keeps it white. This part has an exact answer, which is why it is worth doing properly.

A main image is usually saved as JPEG, which works on 8 × 8 blocks. Take a block whose sixty-four source pixels are all 255. After the level shift (−128) the block is a constant 127, so it has exactly one non-zero DCT coefficient: the DC, equal to 8 × 127 = 1016. All 63 AC coefficients are zero before quantisation and therefore zero after it.

That leaves the DC as the only thing that can move, and it can only move by half a quantisation step. Reconstructed, the block is a flat 255 ± q/16 levels — and because 255 is the top of the range, the upward half of that error clips straight back to 255. The downward half would show up as 254, so this is a claim that can fail, not a tautology.

It does not fail here. Across 13,499 pure-white blocks, at twelve qualities spread from 30 to 100 with chroma left at full resolution, the number of pixels that came out off-255 was zero at every setting — 161,988 blocks, nothing to report. (That is Pillow's bundled libjpeg-turbo. A different IDCT is a different encoder, and the test is cheap enough to re-run.)

So the prediction is not "white stays white approximately". It is: a pure-white block decodes to exactly 255, whatever the quality, as long as chroma is not subsampled. Any deviation is a finding rather than noise, and it can only come from a block that is not pure white — one that touches the product.

White pixels that JPEG changed, by distance from the product, at quality 90; and the pure-white-block count per quality with and without chroma subsampling

The composite has 22,500 blocks, and 13,499 of them are pure white in the source. Four qualities out of the twelve I swept, with chroma subsampling on and off:

quality 4:4:4: dirty pixels in pure-white blocks 4:2:0 share of white dirtied, 4:2:0
95 0 32 0.33%
90 0 111 0.55%
80 0 45 0.63%
70 0 137 1.29%

Zero in the first column at every quality, over 13,499 blocks and 886,539 white pixels. That is not a tolerance, it is the transform behaving exactly as advertised, and it means the check "is the background still 255" has a definite answer that depends only on the encoder settings.

With 4:2:0 it does not. Chroma is stored at half resolution, so a 2 × 2 chroma sample is shared across four luma blocks, and a sample that straddles the product's edge carries its colour outward. The count of affected pure-white blocks is non-zero — and it is not monotone in quality: 32 at q95, 111 at q90, 45 at q80, 137 at q70, and 8 even at q100.

That is not noise. Quality changes the quantisation table, which changes how a shared chroma sample rounds, and the same physical bleed can round to a clean value at one setting and a dirty one at the next. "Save at quality 90" is not a fix for chroma bleed. It is a different rounding of the same leak.

Where the dirt lands

Bucketing the dirtied pixels by chebyshev distance from the product, at quality 90:

distance from the product 4:4:4 4:2:0
1–2 px 3,519 4,057
3–4 px 435 593
5–8 px 125 295
9–16 px 6 74
17–32 px 0 0
beyond 32 px 0 0

Two things fall out. First, the bleed is local: across twelve encoder settings, from q50 to q100 with and without subsampling, not one dirtied pixel landed beyond 16 px of the product — the 17–32 and beyond-32 buckets are zero in all twelve runs. Second, the far buckets are where subsampling does the most relative damage — 4:2:0 carries 12 times as many dirtied pixels into the 9–16 band as 4:4:4 does at q90 — because the 2 × 2 chroma grid reaches further into the flat area than an 8 × 8 luma block does.

In absolute terms it is 0.46% of the white pixels at 4:4:4 and 0.55% at 4:2:0, which sounds small until you remember that a background check is binary. A pixel at 254 fails a == 255 test, and 4,908 of them at q90 4:2:0 is 4,908 failures — all of them within 16 px of the product, in a band no clean retouch can reach.

If the background requirement is literal, the encoder setting is part of the deliverable, not an afterthought. 4:4:4 keeps a fixed 8 × 8 rule: pure in, pure out.

A short checklist

The four readings, restated as things to measure rather than argue about:

  • Report the aspect. Every conversion between the two 85%s needs it, and above 1.176 the area reading is unsatisfiable. A fill percentage without the aspect is uninterpretable.
  • State the reading. Box area and longest side are reproducible; mask area is not, because it inherits the matte.
  • State the threshold. < 255 and < 250 differ by 20% on the same pixels, and the ratio is set by the matte's mean alpha, not by the product's size.
  • Check the encoder, not the retouch, for a dirty background. Pure-white blocks are exactly preserved at 4:4:4 and are not at 4:2:0, and the damage is confined to within 16 px. Saving at a higher quality re-rounds the chroma leak, it does not remove it.

The instrument

The whole measurement is a few unions of numpy masks. This runs on any file and reproduces the first table:

import numpy as np
from PIL import Image


def readings(path, thresholds=(255, 250)):
    """Every number a fill check needs, from the file alone."""
    a = np.asarray(Image.open(path).convert("RGB"))
    ink = ~(a == 255).all(axis=2)          # threshold 255, the literal reading
    ys, xs = np.where(ink)
    h, w = ink.shape
    bw, bh = xs.max() - xs.min() + 1, ys.max() - ys.min() + 1
    out = {"ink": ink.mean(), "box": bw * bh / (w * h),
           "longest": max(bw / w, bh / h)}
    for t in thresholds:
        out[f"t{t}"] = (a.min(axis=2) < t).mean()
    return out
Enter fullscreen mode Exit fullscreen mode

On my composite it prints ink 38.43%, box 51.21%, longest 85.00%, t250 31.95% — the first table above, from the flattened file, with no matte in sight. The 36.79% does not appear anywhere in the output, and no choice of threshold will make it.

The block test is shorter still, and its self-check is that the first column is zero:

def dirty_blocks(path, q=90, subsampling=2):
    """White-source pixels inside an all-white 8x8 block that JPEG changed."""
    src = Image.open(path).convert("RGB")
    a = np.asarray(src)
    src.save("/tmp/_probe.jpg", quality=q, subsampling=subsampling)
    b = np.asarray(Image.open("/tmp/_probe.jpg").convert("RGB"))
    white = (a == 255).all(axis=2)
    bad = white & (b != 255).any(axis=2)
    H, W = white.shape
    blk = white.reshape(H // 8, 8, W // 8, 8).all(axis=(1, 3))
    dbad = bad.reshape(H // 8, 8, W // 8, 8).sum(axis=(1, 3))
    return int(blk.sum()), int(dbad[blk].sum())
Enter fullscreen mode Exit fullscreen mode

subsampling=0 returns (13499, 0); subsampling=2 returns (13499, 111). The block count is the same because the block grid is the same; the dirty count is the whole difference between a background that survives encoding and one that does not.


The reason I keep measuring this is that "is my main image compliant" sounds like a question about a picture, when it is really four questions about conventions that nothing in the file records. Which fill, which threshold, which matte, which encoder. Each has an answer that a number can settle, and each is invisible in the percentage a checker hands back.

I work on PicViva, where this runs as the product-image compliance check — which is how I ended up with a matte, a composite and a block grid on my desk instead of a checklist. The tests above are the ones I use to decide whether a number the checker reports is a measurement or an artefact of one of those four choices.

Top comments (0)