Technical Deep Dives10 min read

Why a Photo Will Not Cut Out Cleanly, and How to Tell Before You Download Anything

Four measurable properties decide whether a background remover produces a clean edge or a fuzzy band: sharpness, clipping, how abruptly the edges turn over, and whether the subject shares its colours with the background. All four can be measured in a fraction of a second, for free, before a 45 to 192 MB model is fetched.

By · Part of the Image processing and on-device AI topic cluster

A background remover either gives you a crisp cutout or a fuzzy band, and the usual explanation is that the model was not good enough. Often it was not the model. Four properties of the photograph itself decide most of the outcome, all four are measurable, and none of them needs a neural network to measure.

That matters here for an unglamorous reason: our background remover is a 45 to 192 MB download. Spending it on a photo that cannot produce a clean edge is a waste of a connection, and on a metered one it is a waste of money. Photo Check measures the four properties first, in a fraction of a second, with nothing fetched.

One: is there any detail to follow

A cutout edge has to follow something. If the camera never recorded a sharp boundary, no amount of model will find one.

The standard measurement is the variance of the Laplacian. The Laplacian is a small filter that responds to how quickly brightness changes between neighbouring pixels: near zero on a flat region, large on a boundary. Run it across a whole photograph and look at how spread out the responses are. A photo with real fine detail produces a wide spread; a blurred one produces a narrow spread clustered near zero.

One property of that measurement is easy to get wrong, and it is why our tool fixes its working size at 768 pixels on the longest edge rather than using your device's limit. A blur of a fixed physical width covers more pixels in a larger image, so the same photograph measures a different variance at 4096 pixels than at 1536. Measure at the device cap and the same file scores differently on a phone and a laptop. A score that moves with the hardware is not a score.

Two: is any of it already gone

Pixels at pure black and pure white have no detail left. Not dark, not bright: gone. Wherever your subject meets a fully clipped region, there is no boundary in the file for anything to find.

So the exposure measurement here is not "is the histogram nicely spread", which is what our previous attempt at this tool measured and which punishes a correctly exposed photograph of a white product on white. It is the fraction of pixels sitting at or beyond each end of the range. Clipping is a fact about lost information; a narrow histogram is usually a fact about the subject.

Roughly one percent clipped at one end is normal on a real photograph with a specular highlight, so the penalty starts gently and gets steep once a tenth of the frame has lost its detail. A product shot against a blown white backdrop is the common failure, and the fix is a re-shoot, not a filter.

Three: how abruptly do the edges turn over

This is the one that predicts a fuzzy result, and it is the most interesting to measure.

Take the Sobel gradient magnitude across the frame, then take the strongest five percent of it as the edges worth judging. Keep only the pixels that are a local maximum of that magnitude, and for each survivor compare its own magnitude against the mean magnitude of its five-by-five neighbourhood.

That local-maximum step is not decoration, and leaving it out is a mistake worth describing because we made it. A gradient ridge has shoulders, and the shoulders of a strong edge are themselves strong enough to pass a top-five-percent threshold. Counted as edges of their own they each score a low ratio, which drags the average down and reports a knife-edge boundary as soft. On a synthetic one-pixel step our first attempt returned 0.75 on a scale where 1 means "entirely soft".

A clean edge concentrates its gradient into a narrow ridge, so the survivor stands above its own neighbourhood. The exact ceiling is worth stating because it is lower than intuition suggests: a Sobel operator reads the column either side of the pixel it is centred on, so a step from black to white produces two adjacent columns of equal magnitude rather than one. Two of the five columns in the window carry the gradient, the window mean is two fifths of the centre, and the highest ratio any real edge can reach is five halves. A soft edge spreads the same total gradient across a ramp several pixels wide, so every pixel in the window measures about the same and the ratio falls towards one. Those two numbers, 2.5 and 1, are the ends of the scale the tool reports.

Motion blur, shallow depth of field and fine hair all look identical to that measurement, which is correct: they are the same problem. A matting model asked to produce an alpha value for a pixel that is genuinely half subject and half background will produce something in between, and a band of in-between alpha is exactly what a fuzzy cutout is.

Four: does the subject share its colours with the background

Even a sharp edge is hard to find if there is nothing on either side of it to tell apart. A grey cat on a grey sofa has a boundary that a person can see from context and a model frequently cannot.

A cheap proxy for this is to compare the colours near the frame border against the colours in the middle. Bucket each region's pixels into a coarse colour histogram, four levels per channel, then take the halved chi-squared distance between the two. Identical distributions score zero; distributions with nothing in common score one. It is the same arithmetic our scene detection uses between video frames, applied between two regions of one image.

It is a proxy and it has an assumption: that your subject is nearer the middle of the frame than the edges. That holds for product and portrait photographs and fails for a tight crop or a subject in a corner, where it will report the cutout as harder than it is. Which is why our tool reports it as one contribution beside the edge measurement rather than as a verdict of its own, and prints the raw number so you can disagree with it.

Noise is the fifth thing, and it is fixable

Noise deserves its own paragraph because, unlike the four above, something can usually be done about it in the browser.

A grainy boundary reads to a matting model as ambiguous alpha along its whole length, which is why a high-ISO photograph tends to produce a speckled cutout edge rather than a clean one. The grain is not the subject and it is not the background, and the model has no way to know that.

Photo Denoise is an edge-preserving bilateral filter, free, local and with no model to download. It weights each neighbouring pixel twice: once by distance, which is an ordinary blur, and once by how different its brightness is from the centre, which is what stops the averaging from crossing an edge. Run it before a cutout and the boundary the model has to follow is a cleaner one.

It has a real cost and the tool says so rather than hiding it. Skin pores, fabric weave and paper grain live at roughly the same scale as the noise, so a setting strong enough to remove all the grain is usually strong enough to flatten them too. That is the familiar plastic look in an over-denoised portrait, and it is why the strength control exists.

What to do with the four numbers

In order:

  1. If sharpness is the weak one, try AI Deblur on a mild focus miss or camera shake, and accept the result otherwise. Nothing invents detail that was never recorded.
  2. If clipping is the weak one, go back to the original file if you have one. A raw file or a less contrasty export often has the boundary that the JPEG threw away.
  3. If noise is the weak one, denoise first and cut out second.
  4. If edge softness is the weak one, expect a soft band and plan to fix it by hand. The image editor has brush erase and restore and an edge refine pass for exactly that.
  5. If the border and the centre share their colours, expect the model to lose parts of the subject, and plan on the brush.

And if all four are fine, spend the download. That is the decision this whole measurement exists to make cheap.

None of it is AI. It is a Laplacian, a pixel count, a Sobel operator and a chi-squared distance, all of which predate deep learning by decades and all of which run instantly on any device. The model is the expensive part, and knowing whether to fetch it is not.

Applies to NSS Background Remover v2.6.2, the release that was current when this article was published.

Was this article helpful?

Your answer is saved in this browser only. This control makes no network request and does not send the answer to an NSS feedback endpoint.

Found this useful?