How Background Removal by Flood Fill Works
After reading this you will understand how a color-based background remover decides which pixels to erase, how the tolerance and feather settings change the cut, and when this method works well versus when you need a different tool.
What this remover actually does
This tool turns a solid or near-solid background into transparency. It does not "understand" the subject. Instead it starts from the outer edges of the image and floods inward, erasing every pixel whose color is close enough to the background color. When it hits a pixel that differs by more than your chosen tolerance, it stops. The remaining connected region becomes transparent; everything the flood could not reach stays.
Take a logo saved as a JPEG on a white card. The background is roughly (255, 255, 255) but JPEG compression leaves stray pixels at (248, 252, 250) and similar values. A flood fill with a tolerance of about 30 treats all of those as "white enough" and clears them, while the dark logo strokes survive because they sit far outside the tolerance band.
The result is exported as PNG because PNG stores a real alpha channel. JPEG has no transparency, so exporting a cutout as JPEG would just paint the background back in, usually as black or white.
When to use it, and when not
Use this remover when the background is one flat color or a smooth gradient that stays far from the subject's colors: product shots on plain paper, scanned logos, screenshots with a uniform panel, flat illustrations. In those cases a single tolerance value separates background from subject cleanly.
Do not expect good results on busy photographic backgrounds: a person in front of foliage, a car on a textured street, hair against a cluttered room. The colors overlap, so no single threshold divides them. Those cases need a machine-learning matting model that learns what a subject looks like. This tool is deliberately small and runs entirely in your browser, so it does not include such a model.
If the subject touches the image edge and shares a color with the background, the flood can leak into the subject. Leave a margin of background around the subject, or crop so the subject does not run off the frame.
The color distance and tolerance
The core decision is a distance in color space. For a candidate pixel with color (r, g, b) and a background sample (r_0, g_0, b_0), the squared Euclidean distance is:
Here r, g, b are the red, green and blue channel values from 0 to 255, and the subscript 0 marks the reference background color sampled at the image edge. A pixel is erased when its distance is within the tolerance:
T is the tolerance you set. A tolerance of 0 erases only pixels that match the background exactly. A tolerance of 441 covers the entire cube, because the longest diagonal from black to white is \sqrt{255^2 \times 3} \approx 441.7. Practical values sit between 20 and 60.
The intuition: picture every color as a point in a cube 255 units on a side. The tolerance draws a sphere of radius T around the background color. Any pixel inside the sphere is "background enough." A small sphere catches only compression noise; a large sphere starts swallowing the subject.
Worked example with the demo settings
The demo loads a sample image and uses the field defaults: background sampled from the corners, tolerance 30, feather 2 pixels. Here is what happens numerically.
A near-white product background
Suppose the sampled background is (250, 250, 248). Consider three pixels.
- A background pixel at
(245, 248, 246). Distance is \sqrt{5^2 + 2^2 + 2^2} = \sqrt{33} \approx 5.7. Since5.7 \le 30, it is erased. - A soft shadow pixel at
(228, 230, 226). Distance is \sqrt{22^2 + 20^2 + 22^2} = \sqrt{1368} \approx 37.0. Since37.0 \gt 30, it survives. The shadow stays as a faint gray fringe. - A logo pixel at
(40, 60, 120). Distance is \sqrt{210^2 + 190^2 + 128^2} = \sqrt{96584} \approx 310.8. Far outside30, so it survives cleanly.
Raise the tolerance to 40 and the shadow pixel now falls inside (37.0 \le 40), so the shadow disappears too. That single step from 30 to 40 is the difference between keeping and cutting the shadow.
What feathering does at the edge
A hard flood fill produces a jagged, aliased border: each pixel is either fully kept (alpha 255) or fully erased (alpha 0). Feathering softens that boundary by blurring the alpha channel over a small radius, so alpha ramps smoothly from 0 to 255 across the cut.
With a feather of 2 pixels, a pixel one step inside the edge might get alpha 170 instead of 255, and one step outside might get alpha 85 instead of 0. The visible result is an edge that blends into whatever you place it on, rather than a stair-step outline.
Keep feather at 1 or 2 for crisp logos and text. Use 3 or 4 only for photographic subjects where a soft edge looks natural. Too much feather makes the whole subject look like it is dissolving.
Reading the result and fixing it
Look at three things after a cut. First, holes inside the subject: if the subject contains a region the same color as the background (a white shirt on white paper), the flood can reach it through a thin gap and punch a hole. Lower the tolerance or patch the gap by cropping. Second, leftover halos: a light ring around the subject means the tolerance was too low to catch anti-aliased edge pixels. Raise it by 5 to 10. Third, eaten edges: if the subject's outline looks chewed, the tolerance was too high and caught subject pixels near the background color.
The relationship is a trade-off along a single axis. As tolerance rises, more true background is removed but more of the subject is at risk. The chart below shows the pattern for the shadow-and-logo example above.
Try the tolerance yourself
The single most instructive control is the tolerance sphere. Move it and watch which of the three sample pixels get erased.
Common mistakes
Sampling the wrong background color is the most frequent error. If the corner you sample sits on a drop shadow rather than the true background, every distance is measured from the wrong center and the cut looks arbitrary. Sample from a clearly empty area.
Expecting the flood to jump gaps is the second. The fill only spreads through connected pixels. A background region fully enclosed by the subject (the loop of a letter "P", for instance) is never reached from the edges, so it stays filled unless the tool also removes enclosed pockets. Check the counters and the letters.
Trusting a screen preview against a matching background is the third. A white cutout on a white page looks perfect until you drop it on a dark slide and see a white halo. Always preview the cutout on both a light and a dark backdrop before you export.
Related tools
Once the background is gone you often want to finish the image. To stamp a logo or credit onto the cutout, use the Watermark Tool. To hide sensitive detail rather than remove a background, the Blur / Pixelate Redactor covers regions instead of clearing them. If the cutout is headed for a caption joke, the Meme Generator adds top and bottom text.
Frequently asked questions
Why is there a faint outline left around my subject?
Anti-aliased edge pixels are a blend of subject and background, so their color sits partway between the two. At a low tolerance they fall outside the erase sphere and remain as a halo. Raise the tolerance by 5 to 10, or increase feather by one so the ramp covers those pixels.
Can I remove a background that is a gradient?
Sometimes. A smooth gradient works if every part of it stays within one tolerance of the sampled color, which is only true for gentle gradients. A strong sky-to-horizon gradient spans a distance far larger than any safe tolerance, so parts of it survive. Flatten or crop first if you can.
Why does the export have to be PNG?
Transparency lives in the alpha channel, and JPEG has no alpha channel. Saving as JPEG discards the transparency and composites the subject over a solid color, which defeats the purpose. PNG (and WebP) keep the alpha, so the cutout stays transparent.
The whole image turned transparent. What happened?
Your tolerance was high enough to include the subject's colors, so the flood spread through everything. Look at the removal curve: past a certain tolerance the percent removed jumps toward 100. Drop the tolerance back into the 20 to 40 range and re-run.
Are my images uploaded anywhere?
No. Everything runs locally in your browser. The pixels never leave your machine, which is why there is no server-side matting model available here.