Object & watermark removal in the browser with MI-GAN (ONNX in a Web Worker)
Inpainting — painting plausible pixels where you've erased something — used to be a "call a cloud API" feature. It no longer has to be. A compact inpainting model runs comfortably in a browser tab via onnxruntime-web.
Inpainting — painting plausible pixels where you've erased something — used to be a "call a cloud API" feature. It no longer has to be. A compact inpainting model runs comfortably in a browser tab via onnxruntime-web.
Why MI-GAN
For removing a watermark, a date stamp, or an unwanted object, you want a model that is small, permissively licensed, and fast enough on CPU/WASM. MI-GAN (MIT-licensed) fits: it takes the image plus a binary mask of the region to remove and returns a filled image. It's a single forward pass — no diffusion steps — so it's quick.
I/O that trips people up
- The model wants the image and the mask as separate tensors, laid out the way the export expects. Get the channel order and normalization wrong and you get garbage or a hang.
- Work in tiles around each masked region instead of pushing the whole 4K image through the net; stitch results back. Faster and lighter on memory.
- Dilate the mask a few pixels so you also cover the anti-aliased fringe and soft shadow of whatever you're removing — otherwise a faint halo remains.
The freeze, and the fix
The thing nobody warns you about: session.run() on the main thread locks the UI for its whole duration. ort.env.wasm.proxy = true is supposed to offload it, but in a Vite/ESM setup it silently ran on the main thread anyway (I verified with an rAF frame-gap probe — a ~15s stall).
The reliable fix is a dedicated module Web Worker: it lazy-imports onnxruntime-web, sets numThreads = 1, caches models in Cache Storage, and exchanges {id, modelUrl, inputs} / {id, outputs} messages with transferable buffers. After moving inference there, the max main-thread frame gap during inference dropped to half a second, and the progress bar actually animates.
Try it
Free and client-side, no upload or sign-up: roodytools.com/remove-watermark. Brush over what you want gone and the model fills it in.
Part of a browser-only toolbox at roodytools.com.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.