# Background Remover

A static web app for client-side image background removal. No image-upload API, server inference, API key, or per-image processing fee. Internet is needed for the first model download. Ordinary static-host bandwidth/storage costs can still apply.

## Run

Upload this whole folder to a static HTTPS website, or for local testing run:

    python3 -m http.server 8765

Then open http://localhost:8765. Do not double-click index.html: browsers block the required fetches on file://.

Embed on another site with an iframe pointing at your hosted index.html. No build step or npm install is needed. Keep vendor/ alongside the app files. HTTPS or localhost is recommended for browser caching. The sample portrait is illustrative, not a customer's photo.

## Model and runtime

- ISNet general-use ONNX, Apache-2.0, pinned revision 362ef325895d0d088b979de093494da7e6f17047. Model download: 176,213,804 bytes. Downloaded from Hugging Face directly into the browser and cached where supported. No user image is sent there. To self-host weights, download model.onnx and change MODEL_URL in app.js to your local URL.
- ONNX Runtime Web 1.20.1, MIT, bundled under vendor/. Single-threaded WASM avoids requiring special isolation headers.
- RGB normalization, 1024 x 1024 model input and min/max alpha normalization follow the upstream ISNet inference code. Output alpha is resized to original dimensions. PNG output preserves original pixel dimensions, not guaranteed detail precision at every edge.
- Editable erase/restore brush, undo, reset and transparency/light/dark/teal preview. Preview colors are never baked into the PNG.

## Limits

20 MB and 20 megapixels per input. This is a desktop-first app; model inference can consume substantial memory and take a minute or longer on slower devices. Test on the actual site's target devices. It is not a guaranteed remove.bg-equivalent on all images. Glass, motion blur, fine hair and low-contrast boundaries may need manual correction. First-use network requests disclose ordinary network metadata to the model host, not image pixels.

## License notices

Keep ISNet-LICENSE.txt and ONNX-Runtime-LICENSE.txt when redistributing. The app's original code is MIT-licensed; see LICENSE.txt. The included sample is from the model card's Pexels example: https://www.pexels.com/photo/5965592/ . It is for testing; use your own licensed sample before deploying a branded public site.

Sources:
https://huggingface.co/x-Liola-x/isnet-general-use-onnx
https://github.com/xuebinqin/DIS/blob/main/LICENSE
https://github.com/microsoft/onnxruntime/blob/main/LICENSE

Inference reference: https://github.com/xuebinqin/DIS/blob/main/IS-Net/Inference.py

Verification: tested in headless desktop Chrome on a 1024 x 683 portrait. Local inference took about 16 seconds after the model was cached. Hair/clothing/face were retained, with some light edge fringe and tiny stray patches needing touch-up. Layout inspected at 390px and 1280px. PNG encoding, alpha, undo and sample loading tested. This is a working first version, not verified remove.bg quality on every input.

## Solid-background mode
Select Solid background (exact) for flat-background logos. It samples the border color and removes only connected matching pixels, preserving enclosed same-color fills. Adjust tolerance, then click Remove background again. Edge cleanup estimates foreground color and unmixed alpha near the removed boundary. JPEG noise, gradients, holes that do not connect to the border, and thin foreground gaps can need manual touch-up. It is deterministic, not a universal pixel-perfect guarantee. This mode does not load the AI model.

## Experimental High quality mode (v3)
BiRefNet Lite FP32 512, MIT model card, pinned revision 4a3c40c36c94093cc1e724d9ea428b8fa4b57dc7. Downloads the original 183 MB ONNX model directly from Hugging Face. ImageNet normalization, external sigmoid, bilinear matte resize. The browser path is experimental and did not complete inference in the tested 1.8GB environment. Devices reporting under 4GB are rejected with a clear fallback message. Reported memory is only a coarse hint; browser/WASM heap limits can still stop this mode on larger devices. Choose AI photo removal or Solid background if it fails. This does not silently change the current default engine.

Actual BiRefNet outputs were verified using native CPU memory-bounded graph execution, not this direct browser route. They improved the tested logo and portrait, but lost valid leaves and a hand in the busy skull-planter test. These tests do not establish superiority on every image.
https://huggingface.co/studioludens/birefnet-lite-512
https://github.com/ZhengPeng7/BiRefNet/blob/main/LICENSE

## V3.1 local-file fix
The runtime JavaScript, module and WASM files are all included in vendor/. Never copy only index.html. No runtime CDN is required. AI cannot run from file:// because browsers block local module/WASM fetches. The app shows this warning before attempting AI. From the extracted folder run `python3 -m http.server 8765`, then visit http://localhost:8765. Remote model download still needs internet; runtime requests remain same-origin.

Launchers: Windows start-windows.bat uses py -3 or python. Mac start-mac.command uses python3 and opens the browser after two seconds. Keep the terminal open. Python 3 must be installed. These launchers bind only to 127.0.0.1, not the network. Mac may ask for permission to open a downloaded command; if necessary run `bash start-mac.command` in Terminal. Launcher OS-specific UI has not been tested on Windows/macOS here.

## Engine self-test (V3.2)
Click Test AI engine and send a screenshot of its result. The bundled tiny ONNX probe actually computes 21+21 using WASM and checks for 42, without downloading either image model. Green proves engine execution on that browser, not large-model memory/download or removal quality. Red includes the error, URL protocol and browser identifier. file:// receives an explicit unsupported-origin message; use the launcher or HTTP/HTTPS.
