A cutout that looks clean on a white canvas can fall apart the moment you put it on a dark one, or zoom to 200%, or try to match it against another product photo in the same listing.

"Looks clean" is not a measurement. I wanted numbers I could run in CI, compare across runs, and argue about with someone who disagrees.

This post gives you three metrics that each catch a different way a cutout fails, the code to compute them, and real measurements from five versions of the same cutout — including two cases where the numbers disagree in a way that matters.

The setup

One photo: a white ceramic mug on a wood table, 1600x1067 (Unsplash license, free for commercial use). It has a handle with a see-through gap, which is the detail most cutouts destroy.

One real matte: Apple's Vision foreground segmentation (VNGenerateForegroundInstanceMaskRequest), run locally on macOS. It found one foreground instance and returned a proper RGBA image — alpha range 0–255, 9.43% of the canvas opaque, 89.49% clear, 1.08% partial.

Then I derived four degraded variants from that same matte, so every difference in the numbers is caused by the degradation and nothing else:

What it simulates
A the reference matte, untouched
B a free tier capped at 0.25 MP — downscale to 625x417, upscale back bilinearly
C over-smoothed matting — Gaussian blur on alpha, sigma 3
D the handle gap filled in — binary_fill_holes on the mask
E a low-res mask upscaled with NEAREST and hard-cut — the classic stair-step edge

Full disclosure: I work on PicViva, an image tool. This post is not a product comparison — it's the measurement code, and it works on anyone's output.

Metric 1 — transition band thickness

How wide is the ramp from opaque to clear?

Take the partial-alpha pixels (alpha strictly between 5 and 250) and divide their area by the perimeter of the binary mask:

thickness = area(partial pixels) / perimeter(mask >= 128) 

For a band of uniform width hugging the outline, area = width × perimeter, so this ratio recovers the width. I like it because it doesn't depend on which way a normal points — my first attempt sampled alpha along outline normals and returned 20 px for an edge that was obviously narrower, purely because the contour direction flipped sign.

import numpy as np from skimage import measure def transition_width(alpha, opaque=250, clear=5): mask = alpha >= 128 partial = (alpha > clear) & (alpha < opaque) # Crofton perimeter is much less biased on diagonal edges than a 4-neighbour count per = measure.perimeter_crofton(mask) return partial.sum() / per if per > 0 else None 

High = soft, feathered, or smeared. Low = hard. And zero means something is wrong, which is the point of metric 3.

Metric 2 — boundary roughness

A hard edge is not automatically a good edge. Pixel-level stair-stepping is invisible in any area-based metric because the shape covers the same pixels — it just looks jagged.

So compare the outline against a smoothed version of itself:

roughness = perimeter(mask) / perimeter(gaussian_smooth(mask, sigma=2) >= 0.5) 

Smoothing irons out the stairs while keeping the overall shape. A clean curve sits near 1.00. An aliased edge climbs.

from scipy import ndimage from skimage import measure def boundary_roughness(alpha, sigma=2.0): mask = alpha >= 128 raw = measure.perimeter_crofton(mask) smooth = ndimage.gaussian_filter(mask.astype(np.float32), sigma) >= 0.5 return raw / measure.perimeter_crofton(smooth) 

Metric 3 — enclosed detail retention

A handle gap, a hole in a bracket, the loop of a chain: background regions that the subject fully surrounds.

Label the background, discard any component touching the canvas border, and whatever is left is a hole:

def enclosed_holes(alpha, min_px=200): mask = alpha >= 128 lbl, n = ndimage.label(~mask) border = set(lbl[0, :]) | set(lbl[-1, :]) | set(lbl[:, 0]) | set(lbl[:, -1]) areas = [int((lbl == k).sum()) for k in range(1, n + 1) if k not in border and (lbl == k).sum() >= min_px] return len(areas), sum(areas) 

Report the area as per-mille of the opaque area, so the number is comparable across image sizes and subjects.

Results

Variant Band thickness Roughness Enclosed holes
A reference 8.33 px 1.002 1 · 83.2 ‰
B 0.25 MP bilinear 10.71 px 1.001 1 · 83.2 ‰
C Gaussian σ3 15.16 px 1.001 1 · 83.1 ‰
D gap filled 0.00 px 1.002 0 · 0 ‰
E aliased 0.00 px 1.082 1 · 83.6 ‰

Five versions of the same cutout on a checkerboard: reference, low-res bilinear, blurred, hole-filled, aliased

What the numbers actually told me

The reference matte is not sharp, and that's fine. Its transition band is 8.33 px wide. I expected 1–2 px and assumed the measurement was broken. It wasn't — sampling the alpha along a horizontal line through the mug gives a clean gradient: 8, 18, 30, 43, 62, 88, 113, 137, 160, 184, 202… The matte is genuinely soft, and it looks good precisely because it is. "Clean" and "sharp" are different properties, and a metric that rewards a 0-px band would be optimizing for the wrong thing.

Alpha profiles across the same edge for all five variants

Low resolution hurt less than I assumed — when resampled bilinearly. Variant B tripled the pixel budget loss and only moved the band from 8.33 to 10.71 px (+29%). That's because bilinear down/up is a low-pass filter: it blurs, it doesn't jag. If someone tells you a 0.25 MP output is unusable on principle, this is the counter-evidence — at 0.25 MP the failure is softness, not structure.

Roughness stayed flat where it should, and moved where it should. B and C sit at 1.001 — blurring doesn't create stairs. E jumps to 1.082, an 8% longer outline for the same shape. That 8% is the visual stair-stepping, quantified.

The two zeroes are not the same zero. This is the part I'd underline. D and E both report a 0.00 px transition band, and a single-metric check would call them identical. They fail in opposite directions:

  • D throws away the alpha channel entirely — the hole is gone (0 ‰), and the subject gained 1.4 percentage points of opaque area where background used to show through.
  • E keeps the hole but loses all edge information, so the outline is a staircase.

To separate them you have to read band thickness together with roughness and hole retention. Any one metric alone is trivially gameable — by a threshold, by a blur, or by filling holes.

Where these metrics stop

They measure edge geometry, nothing else. They say nothing about:

  • Color contamination — a green fringe from the original background, invisible in alpha.
  • Shadow handling — whether the soft shadow under an object survived or was amputated.
  • Semantic correctness — a matte can have a perfect 8-px band around the wrong object.

So run them as a regression gate, not as an aesthetic judge. Pair them with a human look at the checkerboard plate for anything a number can't see.

Two practical notes if you adopt this:

  1. Never compare thickness across different image sizes without normalizing. The ratio is in pixels here; at half resolution every edge is half as wide.
  2. Fix your thresholds and write them down. I used opaque ≥ 250, clear ≤ 5, mask ≥ 128. Change any of those and the numbers shift. The definitions are the measurement; the definitions are also the thing to argue about.

Reproducing this

The whole thing is three numpy/scipy/skimage functions and about 20 lines of variant generation. Drop your own RGBA output in as variant A and the table above becomes a report on your pipeline.

If you build the CI version, the one thing I'd add that I didn't: sample the metrics per region (subject vs. thin parts) instead of globally. A single global number hides a dead handle behind a great silhouette — which is exactly the failure that made me write this in the first place.