Eight posts in this series have measured the pixels a product photo is made of: the original geometry check, colour contamination, the edge-hue test, its blind spot, a coverage matrix, seven rembg models, what resampling does to them, and what happens when you extend a frame. All of those concern one image in, one image out.
This one is about two images and the step between them.
The step nobody measures
A prompt-edit tool does not edit your photo. It generates a new one — the whole frame, at whatever resolution its decoder likes — and something then has to reconcile that output with the file you sent. Usually the tool shows you only the result, so the reconciliation is invisible, but it always happens, and it has exactly three implementations:
| paste | what it does | what it guarantees |
|---|---|---|
| whole frame | return the output as-is | nothing |
| hard mask | output inside the mask, your file outside | outside is bit-exact |
| soft mask | blend across the boundary over r px | nothing is bit-exact, nothing jumps |
The first is what you get when a tool hands back whatever the model produced. The second is what most pipelines do. The third is what people reach for when the second shows a line.
All three are usually judged by looking at the join. That is the wrong test, and this post is mostly about why — but the honest starting point is that the join is also the only thing you can look at, because the model's output inside the mask has no reference to compare against. The content that should be there was never photographed.
Unless you put it there.
Building a case with an answer
Take a real product photo. Call it clean. Stick an opaque label on it — white fill, dark bars, hard edges, the shape a price tag has. Call that dirty, and note that dirty is what the user actually sends in. Then delete the label with a fill and call the result edited. Now paste edited back onto dirty and score the result against clean.
Every number in this post comes from that. The fill I use is skimage.restoration.inpaint_biharmonic — a fourth-order PDE solve that continues the surroundings smoothly and recovers no structure at all. It is a stand-in for "a plausible continuation", chosen because it is reproducible, deterministic, and clearly not a diffusion model. I am not claiming it represents any specific tool's fill quality; the point of holding it fixed is to isolate the paste.
That isolation needs one more decision. If the mask handed to the model is wrong, the fill is conditioned on the wrong boundary and fails for reasons that have nothing to do with compositing — a mask 4 px too small leaves 4 px of the label as the boundary condition, so the model happily continues the label. Real, and not the subject here. So: the model always gets the correct mask, and the paste gets the mask under test. Whatever changes below is the paste.
import numpy as np from scipy import ndimage as ndi def feather_alpha(mask, radius, mode="centered"): """Alpha from the mask's signed distance. centered the ramp straddles the boundary: half the old pixels survive, half of the new pixels are pushed outside the mask. inward the ramp lies inside the mask: outside stays exactly the input, and the outermost band of the edit is thrown away. """ if radius <= 0: return mask.astype(np.float64) inside = ndi.distance_transform_edt(mask) outside = ndi.distance_transform_edt(~mask) s = inside - outside if mode == "inward": return np.clip(inside / float(radius), 0.0, 1.0) return np.clip(0.5 + s / (2.0 * radius), 0.0, 1.0) def composite(dirty, edited, mask, radius=0.0, mode="centered"): a = feather_alpha(mask, radius, mode)[..., None] return dirty * (1.0 - a) + edited * a Sixteen product photos from the same corpus as the previous post, worked at 320 px square, with the label at 22% of the frame width. Three statistics per run, each calibrated on a synthetic frame where the answer is known — a gradient with texture and one hard vertical edge, no product in it, so a paste that copies must score zero:
| paste | leak | edge error | peak error | ghost |
|---|---|---|---|---|
| truth model, exact mask, f0 | 0.0% | 0.00 | 0.00 | 0.00 |
| truth model, exact mask, f2 | 0.0% | 9.32 | 37.95 | 2.97 |
| truth model, exact mask, f8 | 0.0% | 21.25 | 66.40 | 14.56 |
| truth model, mask 4 px tight, f0 | 0.0% | 61.88 | 155.00 | 28.64 |
| truth model, mask 4 px tight, f8 | 0.4% | 38.65 | 105.19 | 27.80 |
| smooth model, exact mask, f0 | 0.0% | 23.37 | 47.19 | 17.96 |
The first row is the calibration and it holds: zero everywhere, including the two instruments that could most easily be measuring themselves. Each row below departs from it in one controlled way, and every direction is checkable by eye on the synthetic frame before you point it at a photograph.
ghost is the one that needs explanation: error weighted by where the label actually was, using the label's own contrast as the weight. Unweighted error inside the mask would also count the fill guessing slightly wrong, which is not what a blend costs you. Weighted, it answers one question — how much of the thing I deleted is still here.
The check you can run without any of this
There is exactly one thing you can verify with no ground truth, and it is the first thing I would add to any edit pipeline.
def leak(result, dirty, mask, tol=0.5): """How much of the frame outside the mask did the paste change.""" out = ~ndi.binary_dilation(mask, iterations=1) d = np.abs(result - dirty).max(axis=2)[out] return (d > tol).mean(), d.max() You have dirty and you have result. That is enough. Point it at a real output and it tells you whether the pixels you did not ask to change came back unchanged.
It matters because models do not return your file. They return a re-encoding of it, and the re-encoding drifts. Six drifts, all applied to the whole frame, with the fill held perfect:
| what the model did to the untouched pixels | whole-frame paste | hard mask | feather 8 |
|---|---|---|---|
| nothing | 0.00% | 0.00% | 0.00% |
| JPEG q88 | 55.9% | 0.00% | 0.62% |
| JPEG q62 | 98.4% | 0.00% | 0.86% |
| +1.5 levels of global offset | 100.0% | 0.00% | 0.24% |
| +4.0 levels | 100.0% | 0.00% | 1.00% |
| resampled to 98% and back | 39.6% | 0.00% | 0.25% |
A global offset of 1.5 levels is hard to see. You would not find it by looking, and it is not a defect — it is what a round trip through an 8-bit encoder does. It also touches every single pixel of the frame, so a whole-frame paste has replaced 100% of a photo the user asked you to change 5% of.
The hard mask is the only column of zeros, and it is exact rather than small: outside the mask you are copying, not blending, so the number is zero because no arithmetic happened. The feather column is the interesting one. A centred feather pulls the model's output up to r px outside the mask, so it re-introduces exactly the drift the hard mask was avoiding — 0.24% to 1.00% of the frame, depending on the drift. Small, and nonzero, and there is no reason to accept it.
Now the part where this check lets you down.
Four pixels of mask error, 12.8x
Here is the same paste, with the mask deliberately offset and no feather at all. The fill is identical in every row — only the mask used for compositing changes.
| mask | edge error | peak error | ghost |
|---|---|---|---|
| 4 px too small | 83.64 | 211.4 | 74.7 |
| 2 px too small | 66.70 | 195.8 | 65.7 |
| exact | 17.78 | 89.6 | 29.7 |
| 2 px too large | 12.84 | 62.6 | 29.7 |
| 4 px too large | 6.51 | 36.4 | 29.7 |
Going from 4 px too small to 4 px too large is a factor of 12.8 in border error, with the fill held constant. The model contributed nothing to that change. Whatever you believe about how good the fill is, this axis is orthogonal to it and it is the larger axis.
Two things drive it, and they are worth separating.
The first is arithmetic. When the mask is 4 px too small, the 4 px of label that live outside it are copied straight from dirty into the result — the paste never touches them, by design. Their contrast with the background is the label's contrast, around 210 levels on these photos, and they sit exactly in the boundary band that every check looks at. Nothing subtle is happening. You asked the compositor to keep everything outside the mask, and it did.
The second is where the seam lands. When the mask is 4 px too large, the boundary sits 4 px out in clean background, where dirty and clean are the same pixels — so the error profile is flat zero for the first 4 px inward and only then climbs. That shows up as the flat zero stretch in the profile figure below. Enlarging the mask did not improve the fill by a single level; it moved the join to a place where joining is easy.
That is a real gain, and it has a real cost I should name: a larger mask asks the model to repaint more of your photo, and on real content — where the fill is not a PDE that only depends on the boundary — the quality of that repaint degrades as the area grows. My experiment holds the fill fixed, so +4 is an upper bound on what enlarging the mask buys. In practice the curve has a floor somewhere, and it is still much better than being 4 px short.
The asymmetry is the actionable part. A mask that is too large costs you a blend; a mask that is too small costs you the thing you were trying to remove. One of those is a gradient and the other is an object.
Feathering moves the error, it does not remove it
So the mask is too small and there is a visible line. The obvious fix is to feather it: blend over 8 px and the line becomes a gradient, and a gradient is what the eye is good at ignoring.
Here is the error profile across the boundary, median over the 16 photos, for four pastes of the same edit.
The two green curves are the case people never test: a model that returns the truth, so the fill is perfect, and the only variable is the feather. At feather 0 the error is 6.3 at 1 px inside the boundary and 11.7 at 2 px. With an 8 px feather it is 59.2 and 57.3.
A feather over a perfect fill made the result five times worse near the seam. Not because the blend is buggy — because composite multiplies dirty by 1 - a, and inside the mask dirty still contains the label. At a = 0.56 you keep 44% of the thing you were deleting, and the model's perfect answer for the other 56%. The label comes back, at 44% strength, as a soft-edged band.
That is the mechanism, and it does not depend on the model being perfect. It depends on dirty containing something you wanted gone, which is the definition of an edit.
The two orange curves are the case feathering is actually for: a mask 4 px too small. A 16 px feather drops the error 4 px outside from 134 to 84 — a 37% improvement on the number that was screaming — and pushes the error 2 px inside from 25 to 45, an 82% increase. The peak moved from one side of the boundary to the other. The total did not fall; it redistributed.
Which is the whole finding in one sentence: a feather is a low-pass filter on your mask error, and a low-pass filter cannot reduce the amount of error, only its frequency.
Which is why the curves cross
Plot the same 25 runs — five mask offsets by five feather radii — as two statistics and the behaviour is unambiguous.
Both panels slope the same way, and the direction is set by where each row's error was living:
- masks that are too small (−4, −2): error is outside, so a feather that pulls the output outward reduces it — peak 211 → 141, mean 84 → 44
- masks that are exact or too large (0, +2, +4): error is inside, so a feather that pulls
dirtyinward increases it — for +4, peak 36 → 74, mean 6.5 → 24
So feathering is not a quality knob. It is a knob that trades error across the boundary, and whether that trade is good depends on which side you were already wrong on. Set it without knowing that and you are as likely to double the damage as to halve it.
And even on the case it helps, it does not converge. A 16 px feather brings a mask that is 4 px too small from 211 down to 141 on the peak. A mask that is 4 px too large, with no feather at all, is at 36. The feather improved the bad mask by a third and the bad mask is still 3.9x the good one. There is no radius that gets you from the first to the second, because no radius changes where the mask is.
This is also why I dropped the boundary-gradient check I started with. It was the obvious idea: a step at the join shows up as a spike in |∇| on the mask boundary, so measure that and divide by the same on the original. On a correct paste it reads 1.000, which looked like a calibration. Then a smooth fill scored 0.37 — below 1 — because a PDE solve genuinely reduces the gradient at the boundary while making the error worse. The check was measuring smoothness and calling it correctness. If you have seen a seam metric behave confusingly, this is one of the reasons.
What I do with this now
- Draw the mask too large, not too tight. 2 to 4 px of dilation is worth more than any feather. The failure mode of a large mask is a soft edge you can feather later; the failure mode of a small one is a copy of the object you were removing.
- Feather 0 to 2 px, and only if the mask was hand-drawn. At
r = 2the mean border error on an exact mask went from 17.8 to 21.3, and the join does look softer. Softer and less correct are the same change here. - Hard mask, and check the leak. Outside the mask, copying is not a stylistic choice, it is the only thing that makes a verifiable claim: the pixels are identical, and 15 lines prove it. Every other paste is above zero and therefore unfalsifiable.
- Never return the model's frame. A 1.5-level global offset is invisible and touches 100% of the image. If a tool shows you a whole-frame result and calls it an edit, that is the leak you are looking at, whether or not it is visible.
- When you see a halo, measure the peak before you reach for the radius. Mean border error at
d = 0is 17.8 with no feather and 32.3 atr = 16. The peak is 89.6 and 106.6. Both say "leave it alone", and the peak says it louder — a feather's job is to hide a peak, so if you are adding one, know the peak you are trying to hide and its width. If it is 4 px of label, no radius hides it; the object is still there.
What this does not cover
My label has hard edges. A white rectangle against a wall is the worst case for feathering and the best case for the crop-and-copy argument, because the thing being deleted has a sharp boundary at a known place. Real removals — a shadow, a strand of hair, a reflection in a bottle — have soft edges where the boundary is genuinely ambiguous. Feathering those is not the same mistake; it is often the only correct answer, because there is no pixel-exact truth to copy. The numbers above say a feather cannot manufacture correctness, not that soft objects should be composited hard.
The fill is a PDE, not a diffusion model. That matters for the absolute levels and not for the ordering. A better fill lowers every row of every table, and it lowers the exact-mask rows more than the mis-sized ones — which would make the mask axis more dominant, not less. But I have not run it, and I would rather say so than extrapolate.
320 px working width. All of these joins are 1–6 px phenomena. At 2000 px the same 4 px mask error is a fifth of a pixel, and the whole discussion changes scale: the leak check still applies, the ghost still applies, and the 12.8x does not — a 4 px error at 4x resolution is a 1 px error, which is where masks are usually right anyway.
One label, one place, always opaque. I did not test translucent marks, structured occluders (a hand holding the product), or labels that touch the frame edge. Each of those stresses a different part of the pipeline — the frame-edge case especially, since a mask that touches the border has no boundary condition on one side and the fill has to invent one.
And fidelity is still not preference. Everything here scores the result against the photo the label was covering. A paste can be pixel-perfect and look wrong, if the fill underneath was visually the wrong choice. This protocol cannot see that, and it is not trying to.
I work on PicViva, where editing a product photo by prompt has to answer this question on every edit: how much of the frame is the model allowed to touch. That question has a lopsided answer. The mask decides the result far more than the model does — a tight mask with a beautiful fill is worse than a generous one with a mediocre fill, by a factor this post measured. The numbers above are the argument for drawing the mask first and picking the model second.
If you have caught one of these in the wild — an edited listing where the untouched corner is subtly brighter than the original — I would like to know what the leak number was.


