remove-background
Fast, minimal background removal for Python using ONNX segmentation models.
Features
- Uses ONNX Runtime for fast inference (CPU)
- Minimal dependencies: only
onnxruntime,Pillow,numpy - Core image preprocessing and postprocessing written from scratch
- Python API and CLI
- Works with any ONNX segmentation model (ISNet, U2-Net, etc.)
Installation
pip install remove-background
The import name is remove_background:
Usage
Python API
from remove_background import remove_background, get_mask
# Remove background (returns RGBA image)
result = remove_background("input.jpg", model_path="model.onnx")
result.save("output.png")
# Get mask only (returns grayscale image)
mask = get_mask("input.jpg", model_path="model.onnx")
mask.save("mask.png")
CLI
# Remove background
python -m remove_background input.jpg -o output.png -m model.onnx
# Get mask only
python -m remove_background input.jpg --mask-only -m model.onnx
Model Setup
Download an ONNX segmentation model (e.g., ISNet or U2-Net) and place it in your working directory, or pass model_path explicitly.
The model must:
- Accept input shape
(1, 3, H, W)float32 - Output a segmentation mask
(1, 1, H, W)or(1, H, W)
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file remove_background-0.1.0.tar.gz.
File metadata
- Download URL: remove_background-0.1.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fdefc399b2a82c4d647e444f99c35af64e210dd70009890f3661633cf2cc0c73
|
|
| MD5 |
73ef6072a3d9f9a03f756cf0b3ce15d1
|
|
| BLAKE2b-256 |
d8892708b342def83a6ce10a27939dffc29f7ac0365a8092f83b0533e740ff88
|
File details
Details for the file remove_background-0.1.0-py3-none-any.whl.
File metadata
- Download URL: remove_background-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2a0e3bf5e38ec96a257a7a6929bd42e9de8b68db66b96debe52e51f47db5fbf
|
|
| MD5 |
25a4f79993e8f72e44d2bde03384884c
|
|
| BLAKE2b-256 |
64c256158ec299bad218f046b4a52b759a8ac080b6c20eabc2df6a8af7018e7b
|