How accurate is in-browser background removal? Tested on 52 images with exact masks

By Rundong LiPublished 12 min read

The short answer: on 52 test images where we knew the correct cut-out to the pixel, our background remover in automatic mode got 36 near-perfect (at least 90% overlap with the true outline) and failed on 10 (less than 50%). The median overlap was 95%. That is after a change we made during this test: before it, the same images gave 31 near-perfect results and 12 failures, and people did worst of all. What still fails is predictable: clear glass, thin parts like harp strings and spindly stands, pairs of objects, and subjects that sit away from the centre of the frame when the tool can't tell that they are people.

How the tool decides what to keep

Everything runs in the browser on Google's MediaPipe models; the photo is never uploaded. There are two cutting models. A person model (the multiclass selfie segmenter, 16.4 MB) knows hair, skin, clothes and accessories. An object model (MediaPipe's "magic touch" interactive segmenter, 6.2 MB) cuts out whatever lies under one point you give it. Automatic mode has to choose between them, and for the object model it has to choose the point. It uses the centre of the photo, and if you click the original, it uses your click instead.

Until this test, the choice between them came from a face detector (BlazeFace, 0.2 MB): a face meant the person model, no face meant the object model, aimed at the centre. That explains a case from an earlier test, where automatic mode kept only 3.5% of a photo of a wooden church. The person model was never involved. No face was found, so the object model was given the centre pixel, which happened to sit on the roof trim, and it returned the roof trim. One click on the church wall fixed it. The change described below doesn't help here: there is no person in the photo, so it still goes to the centre point and still comes back as 3.5% roof trim.

The face detector had two weaknesses that showed up straight away in our test. It is built for faces close to the camera, so it missed faces in full-length shots, a face under a hat brim and even a head-and-shoulders portrait, which sent those people to the object model and its centre point. And it found a face on a tabby cat, which sent the cat to the person model.

What we did

To measure accuracy you need the right answer for every pixel, and real photos don't come with one. So we made our own: we took 47 photos of people, animals, products, food and statues that had already been cut out by hand and published on Wikimedia Commons as transparent PNGs, and pasted each onto one of 24 real background photos, most of them busy: forest paths, a shop shelf, a church interior, a tangle of tree roots, a street of brightly painted houses. Because we did the pasting, the cut-out's own transparency is the exact answer. All the images are public domain or under Creative Commons licences.

Set A has 33 images and set B has 19. Set B uses 14 new cut-outs plus 5 of the set A people on new backgrounds, in new positions. We ran both sets through the live tool, made a change using what set A showed us, and then ran both sets again. Set B was there to catch a change that only works on the images it was designed on.

For each result we compared the tool's cut-out with the true one in three ways. Overlap (IoU) is the area both agree is subject, divided by the area either calls subject: 1 is perfect, 0 means it kept the wrong thing. Alpha error is the average difference in transparency per pixel, over the whole image. Edge score (boundary F-score) is the share of the outline that lands within 8 pixels of the true outline on a 1,600 × 1,200 image.

Results before and after

Automatic mode, no clicks. 1,600 × 1,200 JPEG composites with exact masks. "Before" is the tool as published; "after" uses a scene model instead of a face detector to decide whether to use the person model. Tested in Chromium 156 on an Apple M2 Mac.
Set A beforeSet A afterSet B beforeSet B afterAll 52 beforeAll 52 after
Mean overlap (IoU)0.7780.8270.7440.7960.7650.816
Median overlap0.9410.9570.9310.9350.9340.951
Mean alpha error2.89%2.18%4.95%4.05%3.64%2.86%
Mean edge score0.7260.7720.7170.7700.7230.771
Near-perfect (IoU ≥ 0.9)19 of 3323 of 3312 of 1913 of 1931 of 5236 of 52
Failed (IoU < 0.5)87431210

The median is much higher than the mean because the results split in two. When the tool picks the right subject, the outline is usually very good: the 36 near-perfect results had a median edge score of 0.93. When it picks the wrong subject, the overlap is close to zero. There isn't much in between. So the number that matters most is how often it picks the right thing, and that is what we changed.

What we changed

We replaced the face detector with a small scene model, DeepLab v3 (2.8 MB, also served from Google's MediaPipe model store). It labels every pixel as one of 20 everyday classes, including person, cat, dog, bottle, chair and screen, or as background. Automatic mode now uses the person model when at least 3% of the frame is labelled person and more of it is person than any other class; otherwise it goes to the object model at the centre, as before. Clicking works exactly as it did. Seven images switched model. Six improved:

Overlap (IoU) with the true cut-out. (A) and (B) are the test sets.
ImageBeforeAfterWhy
Man in a hat walking, church interior (A)0.0020.931Face not detected; the centre point landed on the vaulted ceiling
Official portrait, white uniform, lamp posts behind (B)0.0000.994Face not detected; the tool kept a street lamp
Same portrait, pink wall (A)0.5270.942Face not detected; object model added a plant and a window grille and lost part of the uniform
Woman seated in a white dress, forest path (A)0.8920.991Face not detected; object model added a clump of leaves
Person in a red cap sitting cross-legged (A)0.9410.957Face not detected
Tabby cat, forest path (A)0.8140.978Face detector fired on the cat; person model missed part of it and kept stray twigs

The seventh went the other way, slightly: the seated woman on set B dropped from 0.994 to 0.989, because the person model replaced an object-model cut that was already excellent. One other result moved by 0.001 without switching model, which is run-to-run noise. The remaining 44 were identical to three decimal places. Across the 13 people images, the mean overlap went from 0.663 to 0.852, and failures from 4 to 2. Animals rose from 0.828 to 0.849 because of the cat. Products, food, statues and the glass and thin-part group were untouched, because they took the same path before and after. The cost is download size: a portrait now fetches about 22.4 MB the first time instead of 19.8 MB, and other photos about 12.2 MB instead of 9.7 MB. Speed barely changed: the median time per image over both sets was 2.1 seconds before and 2.2 seconds after.

Both sets together. Near-perfect means overlap of 0.9 or more; failed means less than 0.5.
CategoryImagesMean overlap beforeMean overlap afterNear-perfect afterFailed after
People130.6630.852112
Animals80.8280.84961
Products170.8520.852112
Food and plants50.9300.93040
Statues30.6510.65121
Glass, thin parts, pairs60.5770.57724

An idea that didn't survive set B

Our first attempt went further. Instead of always aiming the object model at the centre, it tried up to ten points (where the scene model saw something, plus a 3 × 3 grid around the middle) and kept the mask that looked most like a subject: confident, clear of the frame edges, near the middle, in agreement with the scene model. On set A this scored better than the final version, a mean overlap of 0.831 against 0.827. On set B it dropped to 0.670, well below the 0.744 the unchanged tool scored. It lost a centred dial gauge and a leaf entirely and cut a computer in half, all of which the plain centre point had got right, because a wrong mask can look just as tidy as a right one. We threw it away and kept only the person check, which uses two thresholds and nothing learnt from our images.

Where it still fails

These are the ten results that stayed below 0.5, described in words because the failure is usually easy to see:

  • Clear glass. On a halogen light bulb it kept the rim of the glass but left large holes where the background shows through, and took a piece of the background alongside (0.477).
  • Thin parts. A gold harp in front of tree roots came back as the roots; the strings and the frame are too thin for the object model to grab at the centre (0.067). A Nintendo Virtual Boy kept its red headset but lost most of the stand, the cable and the controller, and gained a piece of window frame (0.491).
  • Pairs. A pair of ice skates and a pair of trainers each came back as one skate or one shoe (0.439 and 0.468). The object model cuts one object; click the other one and you get that one instead, not both.
  • Camouflage. A small lizard, 1.4% of the frame, on a pile of pale roots: the tool kept the roots (0.086).
  • Subject against similar background. A dark wine bottle in front of a window came back with chunks of the window frame and stone wall attached (0.416).
  • Off-centre and not recognised. A statue on a long jetty was off to one side; the centre point landed on a cloud, and the cloud is what we got (0.041). The man in a hat from the table above, pasted on a different background, wasn't recognised as a person there, and the tool kept a wall (0.023).
  • Old black-and-white photo. A 1960 publicity photo of a man in a dark suit wasn't recognised as a person; the object model kept him plus pieces of the stone window beside him (0.387).

In most of those ten, the problem is which thing the tool chose, not the quality of the outline, and that is what a click fixes. In a separate check we ran the object model once from each of 25 grid points on every image and kept the best result: on set B, every image had at least one point that gave an overlap of 0.5 or more, and the best points averaged 0.934. On set A, five images, including the harp, the lizard and the bottle, had no grid point that reached 0.5, and those are the cases to finish by hand.

Download size and speed

File sizes as served by jsDelivr and Google's model bucket. Each file is downloaded once and then served from the browser cache. A session that uses both cutting models now fetches about 28.6 MB in total.
FileSizeWhen it's fetched
MediaPipe runtime (WebAssembly and loader)3.2 MBAlways
DeepLab v3 scene model (new)2.8 MBAutomatic mode, every photo
BlazeFace face detector (removed from this tool)0.2 MBWas: automatic mode, every photo
Selfie multiclass person model16.4 MBWhen a person is found
Magic touch object model6.2 MBNo person found, or you click

Across both sets, time from choosing the file to the finished cut-out was a median 2.2 seconds for the object model and 3.0 seconds for the person model on the changed tool, and 3.7 seconds at worst, on a 1,600 × 1,200 image. Caching was off in our test browser, so every run also fetched the models over a fast connection; on a slow connection the first run takes longer.

What this means in practice

  • For people, pets, and single products that stand clear of the background, automatic mode is usually right, with outlines good enough for a profile picture, a listing or a collage.
  • If the result is the wrong thing, don't try again: click the subject on the original. It reruns from your click and doesn't count against the free daily allowance.
  • Put the subject near the middle of the frame if you can. Use Crop Image first if it isn't.
  • Expect to touch up glass, fine strands and anything with gaps, and photograph pairs together as one shape or cut them out one at a time.
  • For an ID photo, the passport photo maker uses the same person model with the official size and background rules built in. If a form won't take a transparent PNG, PNG to JPG fills the background with white.

How we tested

Cut-outs: 47 transparent PNGs from Wikimedia Commons, mostly from its people, animals and objects with transparent background categories, chosen to be photographs rather than drawings: 9 public domain, 9 CC0 and 29 under CC BY or CC BY-SA. Backgrounds: 24 photos from Commons' Quality Images, under CC BY-SA or CC0, chosen to avoid people or animals that could be mistaken for the subject. Each cut-out was trimmed to its visible pixels, scaled to between 50% and 80% of the frame height (no more than 75% of the width), and placed at a random spot within 15% of the centre horizontally and 10% vertically; head-and-shoulders portraits were placed on the bottom edge. The background was scaled and cropped to 1,600 × 1,200. We blended with the cut-out's own transparency and saved the result as a JPEG at quality 92, and the transparency as the true mask. The list of every file with its licence and author is kept with our test notes.

We ran each image through the published Remove Background page, automatic mode, no clicks, in Chromium 156 on an Apple M2 Mac with 24 GB of memory, with only the site, jsDelivr and Google's model bucket reachable. The changed version was built from the same code with the change applied and served locally in the same way. We saved the PNG it produced, which is the full 1,600 × 1,200, and compared its transparency with the true mask. Overlap counts a pixel as subject when its opacity is above 50%. Edge score compares the outlines of those two shapes, counting a point as matched within 0.4% of the image diagonal (8 pixels). Time runs from choosing the file to the result appearing.

Limits: pasted-in subjects are not real photos. Their lighting, shadows and focus don't match the background, and their edges come from whoever cut them out, which may make them easier to separate than a subject photographed in place, or harder, where a hand-made edge is rough. Set B reuses five set A people, so it is not a fully independent check for people. 52 images is a small sample, with only 6 in the glass and thin-parts group. We tested automatic mode only, one browser, one machine and one image size; models run on the CPU, and a slower phone will take longer. Overlap rewards getting the bulk right and says little about hair; the edge score helps there, but 8 pixels is a forgiving tolerance on fine strands. And the scene model knows only 20 classes, so a person it doesn't recognise, such as the man in a hat on one background, still goes to the object model and its centre point.

Tools mentioned in this article

More from the blog