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.

📦 PyPI: https://pypi.org/project/bgremove-tool/
📚 Repository: https://github.com/memamun/bgremove
👤 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

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License

Copyright (c) 2026 MAMUN

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

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.1.tar.gz (8.5 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.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: bgremove_tool-0.1.1.tar.gz
  • Upload date:
  • Size: 8.5 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.1.tar.gz
Algorithm Hash digest
SHA256 7b15078c48495b09cb61cece2edf8b86d71d902f1e9c1837423bad89adf7749d
MD5 d75115334a98235c2b2c0ab16959f8c4
BLAKE2b-256 a055daaba647f3ea14ec572d172b48886e89eb8b876d27980f0a86a884f340f6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bgremove_tool-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ddee8a1a84bf0e8573880cc614ccf83f7fb24856bbff0fb6b025932f2363f269
MD5 36dc020fd3e2b28fb782e089b0ef3b61
BLAKE2b-256 25dbb78a34557f72b8864eea220f4364ed64677e24c6fbf098da6ee622cf7f79

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