Skip to main content

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

remove_background-0.1.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

remove_background-0.1.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

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

Hashes for remove_background-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fdefc399b2a82c4d647e444f99c35af64e210dd70009890f3661633cf2cc0c73
MD5 73ef6072a3d9f9a03f756cf0b3ce15d1
BLAKE2b-256 d8892708b342def83a6ce10a27939dffc29f7ac0365a8092f83b0533e740ff88

See more details on using hashes here.

File details

Details for the file remove_background-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for remove_background-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2a0e3bf5e38ec96a257a7a6929bd42e9de8b68db66b96debe52e51f47db5fbf
MD5 25a4f79993e8f72e44d2bde03384884c
BLAKE2b-256 64c256158ec299bad218f046b4a52b759a8ac080b6c20eabc2df6a8af7018e7b

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page