Edge quality
The two clean-up passes that run after the model, speck removal and hair colour recovery, with every threshold and how to check edges before you download.
Two clean-up passes run after the segmentation model and before the PNG is written. Speck cleanup removes detached bits of background the model was unsure about. Colour recovery replaces the old background colour inside semi-transparent edge pixels, which is what removes the dark or white halo around hair. Both are automatic and there is nothing to configure; this page documents what they do so you can predict the result.
What does speck cleanup remove?
Pale or cream patches of background that look a bit like the subject often come back from the model as faint, detached islands. Speck cleanup keeps the subject and whatever is close enough to be its hair, and drops the rest. It works on the model's probability map at 1024×1024, in this order:
- Every pixel scored 0.5 or higher counts as subject. Touching pixels (including diagonals) are grouped into regions.
- The largest region is the subject. Any region at least 2% of its size is kept too, so a separated arm or a second product survives.
- Smaller regions are deleted outright.
- Soft alpha is allowed to reach a limited distance beyond the kept regions, for hair, fur and motion blur. Anything farther out is zeroed.
- Finally the levels are stretched: near-zero values become fully transparent and near-one values become fully opaque, so haze disappears and the body of the subject is solid.
If no pixel reaches 0.5 at all (a very faint, low-contrast subject), only the levels step runs, rather than erasing a subject the model was merely unsure about.
The two models get different settings, because IS-Net leaves more haze near the subject than BiRefNet does:
| Setting | BiRefNet (GPU) | IS-Net (CPU) |
|---|---|---|
| Subject threshold | 0.5 | 0.5 |
| Keep regions at least this share of the largest | 2% | 2% |
| How far soft alpha may reach past the subject | 24 px on the 1024 grid | 16 px |
| Band where faint alpha is still kept | 24 px | 3 px |
| Faint alpha dropped outside that band | none | below 0.35 |
| Becomes fully transparent at or below | 0.03 | 0.06 |
| Becomes fully opaque at or above | 0.97 | 0.97 |
The upshot: on the CPU path, fine hair right at the edge survives, while a veil of haze a little further out over a cream wall is removed. BiRefNet's soft edges are usually real hair, so they are left alone.
Why is there a halo around hair, and how is it removed?
A strand of hair is thinner than a pixel, so an edge pixel that is 40% hair is also 60% whatever was behind it. Keep that pixel's original colour under the new transparency and you keep 60% of the old wall: a dark rim on a light background, a light rim on a dark one. Compositing has worked this way since Porter and Duff (1984).
Colour recovery estimates what colour each partly transparent pixel would be on its own and writes that instead. It follows the two-pass blur-fusion method from Forte and Pitié, "Approximate Fast Foreground Colour Estimation" (ICIP 2021):
- Wide pass, on the 1024 grid with a radius of 45: an average subject colour and an average background colour around every point, each weighted by how much of the pixel belongs to it.
- Narrow pass, at full resolution with a radius that grows with the photo:
round(longer side / 350), clamped between 3 and 12 pixels. That is 5 pixels for a 1920×1080 photo and 11 for one 4000 pixels wide.
Only pixels that are partly transparent change colour. The full-resolution work is done in 256 pixel tiles, and a tile with no partly transparent pixels is skipped, so on a typical photo the cost is a thin band around the subject.
How do I check the edges before downloading?
- Choose Background → Color and pick black. A halo that hides on white or on the checkerboard shows up at once on black.
- In Compare mode, drag the divider slowly along the hairline, or press ← → to step it.
- Hold Space to flash the original and see what the model had to separate.
- Switch to white, or to the colour you plan to use, and look once more.
What can the clean-up not fix?
- Glass, smoke, veils and thin fabric come back partly transparent, because they are. The clean-up does not make them opaque.
- When the subject matches its background (a white product on a white sweep, black hair against a dark doorway), the model may give part of the edge to the background, and colour recovery cannot bring back pixels that were cut.
- Speck cleanup keeps any region bigger than 2% of the subject, so a chair behind a person can stay. Crop the photo first, or remove the extra object afterwards in an editor.
- IS-Net, on the CPU path, is weaker than BiRefNet on hair. For the cleanest hair, use Chrome or Edge on a computer with WebGPU (see Models and hardware).
The guide How AI background removal works, and why hair leaves a halo walks through both faults with a worked pixel example.