withoutbg/withoutbg

Python SDK for local and cloud background removal (pip install withoutbg)

What it solves

It provides a simple way to remove backgrounds from images using Python, offering a choice between running a free, private model locally or using a high-quality cloud-based API.

How it works

The library allows users to instantiate a WithoutBG object in two modes: open_weights() for local processing and api() for cloud processing. The local mode downloads an ONNX model (approximately 455 MB) based on DINOv3 that performs depth, segmentation, matting, and refinement in a single pass on the CPU. The cloud mode sends the image to a remote API for superior results, particularly on complex edges like hair and fur.

Who it’s for

It is designed for developers building scripts, Jupyter notebooks, backends, or batch processing jobs that require automated image background removal.

Highlights

  • Dual-Mode Execution: Switch between local open-weights (free, offline, private) and Cloud API (higher quality) with a single line of code.
  • Batch Processing: Includes a remove_background_batch method to process multiple images efficiently without reloading model weights.
  • Local CPU Support: The local model runs via ONNX, meaning no dedicated GPU is required.
  • CLI Tool: Comes with a command-line interface for quick image processing without writing Python code.
  • PIL Integration: Returns images as PIL Image objects in RGBA mode, making it easy to composite subjects onto new backgrounds.