Thanks to visit codestin.com
Credit goes to github.com

Skip to content

withoutbg/withoutbg

Repository files navigation

withoutbg

AI-powered background removal with local and cloud options

PyPI License Status

Remove backgrounds from images instantly with AI. Choose between local processing (free) or withoutBG Pro (best quality).

⚑ Try It in 30 Seconds

Python Package Intro

# Install and run in one go
pip install withoutbg

# Remove background from your first image
python -c "from withoutbg import WithoutBG; WithoutBG.opensource().remove_background('your-photo.jpg').save('result.png')"

That's it! Your photo now has a transparent background. ✨

πŸ€” Which Option Should I Use?

Processing 1-10 images occasionally? β†’ withoutBG Pro (zero setup, best quality)
Processing 100+ images? β†’ Local model (free, reusable)
Need offline processing? β†’ Local model
Want best possible quality? β†’ withoutBG Pro
Building commercial product? β†’ withoutBG Pro (scalable)
Need fastest processing? β†’ withoutBG Pro (optimized infrastructure)

Compare Focus vs Pro β†’

πŸš€ Quick Start

Docker (Web Interface)

View Complete Dockerized Web App Documentation β†’

Web Applicacation in Docker

docker run -p 80:80 withoutbg/app:latest

# Open in browser
open http://localhost

βœ… Multi-platform support: Works on Intel/AMD (amd64) and ARM (arm64) architectures

Python SDK

View Complete Python SDK Documentation β†’

# Install (using uv - recommended)
uv add withoutbg

# Or with pip
pip install withoutbg

Local Processing (Free):

from withoutbg import WithoutBG

# Initialize model once, reuse for multiple images (efficient!)
model = WithoutBG.opensource()
result = model.remove_background("input.jpg")  # Returns PIL Image.Image
result.save("output.png")

# Standard PIL operations work!
result.show()  # View instantly
result.resize((500, 500))  # Resize
result.save("output.webp", quality=95)  # Different format

withoutBG Pro (Best Quality):

See Pro API Results β†’

from withoutbg import WithoutBG

# Get your API key from withoutbg.com
model = WithoutBG.api(api_key="sk_your_key")
result = model.remove_background("input.jpg")
result.save("output.png")

# Or set environment variable (recommended)
# export WITHOUTBG_API_KEY=sk_your_key
model = WithoutBG.api(api_key="sk_your_key")

CLI:

# Process single image
withoutbg photo.jpg

# Process entire photo album
withoutbg ~/Photos/vacation/ --batch --output-dir ~/Photos/vacation-no-bg/

# Convert to JPEG with white background (for printing)
withoutbg portrait.jpg --format jpg --quality 95

# Use withoutBG Pro for best quality
export WITHOUTBG_API_KEY=sk_your_key
withoutbg wedding-photo.jpg --use-api

# Process and watch progress
withoutbg photo.jpg --verbose

Don't have uv yet? It's a fast, modern Python package installer - get it at astral.sh/uv

Example Outputs from the Open Source Model

See More Focus Model Results β†’

Example 1 Example 5 Example 3 Example 6 Example 4

withoutBG Zoom is coming!

withoutBG Zoom

We are finalizing a new architecture designed to deliver superior accuracy and finer detail. Star the repo to bookmark this upgrade for your future toolkit ⭐.

πŸ“¦ Repository Structure

This is a monorepo containing multiple components:

withoutbg/
β”œβ”€β”€ packages/          # Reusable packages
β”‚   └── python/        # Core Python SDK (published to PyPI)
β”‚
β”œβ”€β”€ apps/              # End-user applications
β”‚   └── web/           # Web application (React + FastAPI)
β”‚
β”œβ”€β”€ integrations/      # Third-party tool integrations
β”‚   └── (future: GIMP, Photoshop, Figma plugins)
β”‚
β”œβ”€β”€ models/            # Shared ML model files
β”‚   └── checkpoints/   # ONNX model files
β”‚
β”œβ”€β”€ docs/              # Documentation
└── scripts/           # Development scripts

Components

πŸ“š Python SDK

Core library for background removal. Published to PyPI.

  • Install: uv add withoutbg (or pip install withoutbg)
  • Use: Python API + CLI
  • Models: Focus v1.0.0 (local), withoutBG Pro

Modern web interface with drag-and-drop UI.

  • Stack: React 18 + FastAPI + Nginx
  • Deploy: Docker Compose
  • Features: Batch processing, live preview

πŸ”Œ Integrations (Coming Soon)

Plugins for popular creative tools.

  • GIMP plugin
  • Photoshop extension
  • Figma plugin
  • Blender addon

🎯 Features

  • ✨ Local Processing: Free, private, offline with Focus v1.0.0
  • πŸš€ withoutBG Pro: Best quality, scalable, 99.9% uptime
  • πŸ“¦ Batch Processing: Process multiple images efficiently
  • 🌐 Web Interface: Beautiful drag-and-drop UI
  • πŸ”§ CLI Tool: Command-line automation
  • 🎨 Integrations: Work in your favorite tools

πŸ’‘ Common Use Cases

Understanding Return Values

All methods return PIL Image objects with transparent backgrounds (RGBA mode):

from withoutbg import WithoutBG

model = WithoutBG.opensource()
result = model.remove_background("photo.jpg")  # Returns PIL Image.Image

# Save in different formats
result.save("output.png")    # PNG with transparency
result.save("output.webp")   # WebP with transparency
result.save("output.jpg", quality=95)  # JPEG (no transparency)

Common Gotchas

JPEG Files Don't Support Transparency:

# ❌ This loses transparency (JPEG doesn't support alpha):
result.save("output.jpg")

# βœ… Use PNG or WebP for transparency:
result.save("output.png")  # Keeps alpha channel
result.save("output.webp")  # Also works!

Model Downloads Happen on First Run:

# First run: ~5-10 seconds (downloading ~320MB of models from HuggingFace)
model = WithoutBG.opensource()  # Downloads models to cache

# Second run: Instant! (models cached locally)
model = WithoutBG.opensource()  # Uses cache
result = model.remove_background("photo.jpg")  # Now processes in ~2-5s

Output File Naming:

  • Single file: photo.jpg β†’ photo-withoutbg.png
  • Batch: Creates photo1-withoutbg.png, photo2-withoutbg.png, etc.
  • Custom: Use --output or --output-dir to specify

Batch Processing (Efficient Model Reuse)

from withoutbg import WithoutBG

# Initialize model once - loaded into memory
model = WithoutBG.opensource()

# Process multiple images - model is reused (much faster!)
images = ["photo1.jpg", "photo2.jpg", "photo3.jpg"]
results = model.remove_background_batch(images, output_dir="results/")
# Returns list of PIL Image objects

Progress Tracking

def show_progress(progress):
    print(f"Processing: {progress * 100:.0f}%")

model = WithoutBG.opensource()
result = model.remove_background("photo.jpg", progress_callback=show_progress)

Error Handling

from withoutbg import WithoutBG, APIError, WithoutBGError

try:
    model = WithoutBG.api(api_key="sk_your_key")
    result = model.remove_background("photo.jpg")
    result.save("output.png")
except APIError as e:
    print(f"API error: {e}")
except WithoutBGError as e:
    print(f"Processing error: {e}")

⚑ Performance

Metric Local (CPU) withoutBG Pro
First Run 5-10s (~320MB download) 1-3s
Per Image 2-5s 1-3s
Memory ~2GB RAM None
Disk Space 320MB (one-time) None
Setup One-time download API key only
Cost Free forever Pay per use

Model Files (cached after first download):

  • ISNet segmentation: 177 MB
  • Depth Anything V2: 99 MB
  • Focus Matting: 27 MB
  • Focus Refiner: 15 MB
  • Total: ~320 MB (one-time download, cached locally)

πŸ’‘ Pro Tip: For batch processing, initialize the model once and reuse it - this is 10-100x faster than reinitializing for each image!

πŸ”§ Troubleshooting

Model download fails?

  • Check your internet connection
  • Models are downloaded from HuggingFace on first run (~320MB total)
  • Or use local model files (see Configuration)

Out of memory?

  • Try processing smaller images or use withoutBG Pro
  • Reduce batch size when processing multiple images

Import errors or "module not found"?

# Make sure you're in the right environment
which python  # Check your Python path
pip list | grep withoutbg  # Verify installation

# If using virtual environment
source venv/bin/activate  # Activate first
pip install withoutbg  # Then install

API key invalid?

  • Get your API key from withoutbg.com
  • Set environment variable: export WITHOUTBG_API_KEY=sk_your_key

Slow processing on first run?

  • Normal! Models are being downloaded (~320MB)
  • Subsequent runs will be much faster (~2-5s per image)

πŸ“– Documentation

πŸ› οΈ Development

Python Package

cd packages/python

# Install in development mode (using uv - recommended)
uv sync --extra dev

# Or with pip
pip install -e ".[dev]"

# Run tests
pytest

# Format code
black src/ tests/
ruff check src/ tests/

Web Application

# Development mode (hot-reload)
docker-compose -f apps/web/docker-compose.yml up

# Or run components separately
cd apps/web/backend
uv sync
uvicorn app.main:app --reload

cd apps/web/frontend
npm install
npm run dev

🌟 Latest Release: Focus v1.0.0

Our most advanced open source model with:

  • βœ… Significantly better edge detail - Crisp, clean edges
  • βœ… Superior hair/fur handling - Natural-looking fine details
  • βœ… Better generalization - Works on diverse image types

See example outputs above and check sample-results/ for more visual comparisons.

πŸ“„ License

Apache License 2.0 - see LICENSE

Third-Party Components

  • Depth Anything V2: Apache 2.0 License (only vits model)
  • ISNet: Apache 2.0 License

Acknowledgements

See THIRD_PARTY_LICENSES.md for complete attribution.

🀝 Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

πŸ“§ Support

⭐ Star History

Star History Chart