Remove image background using advanced AI models including U-Net, BiRefNet, and SAM with support for multiple input formats and GPU acceleration
84
Comprehensive CLI tools for batch image processing, folder monitoring, HTTP server functionality, and model management. The CLI provides a complete interface to rembg's capabilities without requiring Python programming.
pip install rembg[cli]Process individual image files with full control over model selection and processing options.
rembg i [OPTIONS] INPUT OUTPUT
Options:
-m, --model [u2net|u2netp|u2net_human_seg|u2net_cloth_seg|u2net_custom|birefnet_general|birefnet_general_lite|birefnet_portrait|birefnet_dis|birefnet_hrsod|birefnet_cod|birefnet_massive|dis_anime|dis_custom|dis_general_use|sam|silueta|bria_rmbg|ben_custom]
Model name (default: u2net)
-a, --alpha-matting Use alpha matting for higher quality
-af, --alpha-matting-foreground-threshold INTEGER
Trimap foreground threshold (0-255, default: 240)
-ab, --alpha-matting-background-threshold INTEGER
Trimap background threshold (0-255, default: 10)
-ae, --alpha-matting-erode-size INTEGER
Alpha matting erosion size (default: 10)
-om, --only-mask Return only the binary mask
-ppm, --post-process-mask Apply post-processing to mask
-bgc, --bgcolor "R G B A" Background color (space-separated, e.g., "255 255 255 255")Usage Examples:
# Basic usage
rembg i input.jpg output.png
# Use specific model
rembg i -m birefnet_portrait portrait.jpg output.png
# High-quality with alpha matting
rembg i -a input.jpg output.png
# Get only the mask
rembg i -om input.jpg mask.png
# Custom background color (white)
rembg i -bgc "255 255 255 255" input.jpg output.jpgBatch process entire folders of images with support for parallel processing and progress tracking.
rembg p [OPTIONS] INPUT_FOLDER OUTPUT_FOLDER
Options:
-m, --model [model_names...] Model name (default: u2net)
-a, --alpha-matting Use alpha matting
-af, --alpha-matting-foreground-threshold INTEGER (default: 240)
-ab, --alpha-matting-background-threshold INTEGER (default: 10)
-ae, --alpha-matting-erode-size INTEGER (default: 10)
-om, --only-mask Return only masks
-ppm, --post-process-mask Apply post-processing
-bgc, --bgcolor TEXT Background color
-w, --watch Watch folder for new files
-d, --delete_input Delete input files after processingUsage Examples:
# Process entire folder
rembg p input_photos/ output_photos/
# Watch folder for new files
rembg p -w input_photos/ output_photos/
# Batch process with alpha matting
rembg p -a photos/ processed/Process RGB24 pixel data streams, typically from video processing pipelines like FFmpeg.
rembg b [OPTIONS] IMAGE_WIDTH IMAGE_HEIGHT
Arguments:
IMAGE_WIDTH Width of input images in pixels
IMAGE_HEIGHT Height of input images in pixels
Options:
-m, --model [model_names...] Model name (default: u2net)
-a, --alpha-matting Use alpha matting
-af, --alpha-matting-foreground-threshold INTEGER (default: 240)
-ab, --alpha-matting-background-threshold INTEGER (default: 10)
-ae, --alpha-matting-erode-size INTEGER (default: 10)
-om, --only-mask Return only masks
-ppm, --post-process-mask Apply post-processing
-bgc, --bgcolor "R G B A" Background color (space-separated)
-x, --extras TEXT Extra parameters as JSON
-o, --output_specifier TEXT Printf-style output filename patternUsage Examples:
# Process RGB24 stream from FFmpeg
ffmpeg -i input.mp4 -ss 10 -an -f rawvideo -pix_fmt rgb24 pipe:1 | rembg b 1280 720 -o output-%03u.png
# Process with specific model
ffmpeg -i video.mp4 -f rawvideo -pix_fmt rgb24 pipe:1 | rembg b -m birefnet_general 1920 1080 -o frame_%04d.png
# Output to stdout
ffmpeg -i video.mp4 -f rawvideo -pix_fmt rgb24 pipe:1 | rembg b 1920 1080 > processed_frames.binRun rembg as a web service with REST API endpoints for integration with other applications.
rembg s [OPTIONS]
Options:
--host TEXT Server host (default: 0.0.0.0)
--port INTEGER Server port (default: 7000)
--log_level [DEBUG|INFO|WARNING|ERROR|CRITICAL]
Logging level (default: INFO)
--threads INTEGER Number of worker threadsUsage Examples:
# Start server on default port 7000
rembg s
# Start server on custom port
rembg s --port 8080
# Start with debug logging
rembg s --log_level DEBUGAPI Endpoints:
# Remove background from uploaded image
POST /api/remove
Content-Type: multipart/form-data
Body: file=<image_file>, model=<model_name>
# Health check
GET /api/health
# List available models
GET /api/modelsDownload and manage AI models locally for offline usage.
rembg d [MODEL_NAMES...]
Arguments:
MODEL_NAMES: Space-separated list of model names to download.
If none specified, downloads all available models.
Available models:
u2net, u2netp, u2net_human_seg, u2net_cloth_seg, u2net_custom,
birefnet_general, birefnet_general_lite, birefnet_portrait,
birefnet_dis, birefnet_hrsod, birefnet_cod, birefnet_massive,
dis_anime, dis_custom, dis_general_use, sam, silueta,
bria_rmbg, ben_customUsage Examples:
# Download specific models
rembg d u2net birefnet_portrait
# Download all models
rembg d
# Download model family
rembg d birefnet_general birefnet_general_lite birefnet_portraitAll processing commands support these common options:
rembg p) for multiple imagesrembg b) for video pipelinesInstall with Tessl CLI
npx tessl i tessl/pypi-rembgevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10