In earlier articles we showed how to run a depth map and a background cutout directly on the user's GPU with WebGPU. This time we went a step further: a demo where you click on the people you want to remove from a photo and the AI doesn't just cut them out, it fills the gap realistically, like the "magic eraser" in photo apps, but running entirely in your browser, with the image never leaving your device.
What the Demo Does
- You upload a photo (or use the sample one).
- You click on each person you want to remove. A segmentation model instantly highlights that person's full silhouette.
- You press "Eliminar seleccionadas" (Remove selected). A second model fills the empty area with a background consistent with the rest of the image.
- You compare before and after with a slider, and download the result.
Why Two Models (and Two Different AI Engines)
Removing someone from a photo convincingly is actually two different problems:
- Knowing which pixels belong to that person (segmentation). For this we use SlimSAM, a lightweight version of Segment Anything (Meta's click-based segmentation model) ported to run in the browser. With a single click we get a precise mask of the object under the cursor.
- Filling the gap left behind (inpainting). For this we use MI-GAN, a much lighter and faster model than diffusion-based alternatives, designed specifically for mobile and browser.
No single model does both well, so instead of forcing one, we use the most suitable model for each task. That means combining two different inference engines in the same demo: Transformers.js for SlimSAM and ONNX Runtime Web (with its WebGPU backend) for MI-GAN, both loaded from a CDN and run entirely on your graphics card.
How It Works Under the Hood
Click-based segmentation has a performance trick that makes it viable in the browser: instead of reprocessing the whole photo on every click, the AI computes the image embeddings just once when it loads. Each subsequent click only runs the "lightweight" part of the model (the decoder), so the result appears almost instantly even if you click several times.
Quitar personas de una foto
All of this inference (loading the models, computing the embeddings, decoding each click and running the inpainting) runs on your graphics card via WebGPU. Because the GPU does the heavy lifting rather than the CPU, the interface stays responsive even if you click several times in a row, and because the embeddings are computed only once, every later click is almost instant. None of it travels to a server: the two models are downloaded once from a CDN, stay in the browser cache, and from then on everything happens locally.
An Honest Limitation
SlimSAM doesn't "know" what a person is: it segments whatever is under the point where you click, whether a person, an object or an animal. It works very well when you click on someone, but it is not a dedicated person detector. If the result isn't exactly what you expected, try clicking on a different point of the silhouette.
How This Fits into What We Do at Fastex
This demo is another example of our philosophy on in-browser AI: instead of sending the photo to a server (with the cost, latency and privacy risk that implies), we use the GPU the user already has in front of them to solve the problem on the spot. For each part of the problem, we choose the smallest, fastest model that solves that part well, exactly the same engineering criterion we apply in client projects.
At Fastex we design AI architectures that balance performance, cost and privacy. If you want to explore client-side AI for your product, let's talk through the contact form.