Skip to main content

AI-powered background removal CLI tool - Remove image backgrounds from command line

Project description

BG Remove Tool - Command Line Interface

A powerful command-line interface (CLI) tool for AI-powered background removal from images. Process single images or entire directories with simple commands.

Author: MAMUN (a.a.mamun595@gmail.com)

🚀 Quick Start

# Install from PyPI
pip install bgremove-tool

# Remove background from an image
bgremove photo.jpg

# Process multiple images in a directory
bgremove --input-dir ./photos --output-dir ./results

# Get help
bgremove --help

Note: Install with pip install bgremove-tool, then use the bgremove command. This is a command-line tool, not a Python library.

Features

  • Remove backgrounds from single images or batch process directories
  • Smart output file naming: "_transparent.png" suffix for most files, "_bgremoved.png" for files already containing "transparent"
  • Always outputs PNG format for transparency support
  • Support for multiple input formats (PNG, JPG, JPEG, BMP, TIFF, WEBP)
  • Overwrite protection with optional force overwrite
  • Error handling and informative messages

Installation

Option 1: Install as Python Package (Recommended)

  1. Clone this repository

  2. Install the package:

    pip install -e .
    # or if using uv:
    uv pip install -e .
    

    This will install the bgremove command globally.

Option 2: Run Directly (Cross-platform)

  1. Clone this repository

  2. Install dependencies:

    pip install -r requirements.txt
    # or if using uv:
    uv sync
    
  3. Use the appropriate launcher for your OS:

    • Linux/macOS: ./bgremove.sh
    • Windows: bgremove.bat
    • Any OS with Python: python bgremove.py

Option 3: Direct Python Execution

python main.py [arguments]

Usage

Remove background from a single image

# If installed as package:
bgremove image.jpg

# Using launchers:
./bgremove.sh image.jpg          # Linux/macOS
bgremove.bat image.jpg           # Windows
python bgremove.py image.jpg     # Any OS

# Direct execution:
python main.py image.jpg

This will create image_transparent.png in the same directory.

Specify output file

bgremove image.jpg -o output.png

Overwrite existing output file

bgremove image.jpg --overwrite

Batch process a directory

bgremove --input-dir ./images --output-dir ./output

This will process all supported images in ./images and save results to ./output.

Get help

python main.py --help

Command Line Options

  • input: Input image file path (required for single file processing)
  • -o, --output: Output file or directory path
  • --input-dir: Input directory containing images to process
  • --output-dir: Output directory for processed images
  • --overwrite: Overwrite existing output files

Supported Formats

  • PNG
  • JPG/JPEG
  • BMP
  • TIFF/TIF
  • WEBP

Cross-Platform Launchers

This tool provides multiple ways to run it on different operating systems:

OS Command Description
Any OS bgremove If installed as Python package
Linux/macOS ./bgremove.sh Shell script launcher
Windows bgremove.bat Batch file launcher
Any OS python bgremove.py Python launcher script
Any OS python main.py Direct Python execution

Requirements

Minimum Requirements (CPU)

  • Python 3.14+
  • Memory: At least 4GB RAM (8GB recommended for large images)
  • Storage: ~200MB for AI models (downloaded automatically on first use)
  • Processing: May take 10-30 seconds per image depending on hardware
  • rembg[cpu] (includes ONNX Runtime for CPU inference)
  • numpy
  • pillow

GPU Requirements (Optional - Faster Processing)

  • CUDA-compatible GPU (NVIDIA)
  • Additional ~2GB VRAM
  • PyTorch with CUDA support
  • rembg[gpu] (includes GPU-accelerated ONNX Runtime)
  • torch>=1.9.0
  • torchvision>=0.10.0

⚠️ Performance Note: The AI model loads ~500MB into memory. First run downloads models and may be slow. Close other memory-intensive applications.

Distribution & Packaging

For Developers - Building the Package

Using Modern Python Packaging (Recommended)

# Install build tool
pip install build

# Build distributions
python -m build

# This creates:
# dist/bgremove-0.1.0.tar.gz (source distribution)
# dist/bgremove-0.1.0-py3-none-any.whl (wheel)

Upload to PyPI

# Install upload tool
pip install twine

# Upload to PyPI (requires account)
twine upload dist/*

For End Users - Installation Options

Option 1: Install from PyPI (when published)

# CPU version (default)
pip install bgremove

# GPU version (if you have CUDA-compatible GPU)
pip install bgremove[gpu]

bgremove image.jpg

Option 2: Install from Source

# Clone repository
git clone https://github.com/bgremove/bgremove.git
cd bgremove

# CPU version (default)
pip install -r requirements.txt
pip install -e .

# GPU version (optional, requires CUDA-compatible GPU)
pip install torch torchvision rembg[gpu]

# Use the command
bgremove image.jpg

Option 3: Standalone Usage (No Installation Required)

# Download/clone the repository
git clone https://github.com/bgremove/bgremove.git
cd bgremove

# Install dependencies
pip install -r requirements.txt

# Use appropriate launcher for your OS:
./bgremove.sh image.jpg          # Linux/macOS
bgremove.bat image.jpg           # Windows
python bgremove.py image.jpg     # Any OS with Python

Package Contents

  • bgremove/: Main Python package
  • bgremove.sh: Linux/macOS launcher script
  • bgremove.bat: Windows launcher script
  • bgremove.py: Universal Python launcher
  • pyproject.toml: Modern Python packaging configuration
  • setup.py: Traditional setuptools configuration
  • requirements.txt: Dependencies list
  • README.md: Documentation
  • LICENSE: MIT license

License

Add your license here

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bgremove_tool-0.1.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

bgremove_tool-0.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file bgremove_tool-0.1.0.tar.gz.

File metadata

  • Download URL: bgremove_tool-0.1.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for bgremove_tool-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e5ea09ea2cdbf86f48799baebad16a2c26101523edfa6a2b02678ed0ad128f79
MD5 6bb7b8437e2cb3db4684c2b7339f9043
BLAKE2b-256 fb3794a34eba53653f989dae7c46dc97a0d08c364a7651b14bd6812aefc8df44

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bgremove_tool-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for bgremove_tool-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ded94db6f6d08f3d904d2bdc65721b971d57f67cbdb0b1936815db8a8792b60e
MD5 1dc993633225e65e3a943cc296ecb3d7
BLAKE2b-256 ba33fb372521f4483402df3a0d93486f38114dfbe9eaf146d49f125a5a5ed0ae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page