background-remover
Remove backgrounds from images using segmentation. Support for color-based, edge detection, and AI-assisted removal methods. Batch processing available.
How do I install this agent skill?
npx skills add https://github.com/dkyazzentwatwa/chatgpt-skills --skill background-removerIs this agent skill safe to install?
- Gen Agent Trust Hubpass
The background-remover skill is a legitimate image processing tool designed to remove and replace backgrounds in images. It utilizes well-established Python libraries such as OpenCV and Pillow. No malicious patterns, such as prompt injection, data exfiltration, or unauthorized code execution, were detected during the analysis.
- Socketpass
No alerts
- Snykpass
Risk: LOW · No issues
- Runlayerwarn
3/3 files flagged
What does this agent skill do?
Background Remover
Remove backgrounds from images using multiple detection methods.
Features
- Color-Based Removal: Remove solid color backgrounds
- Edge Detection: Detect subject edges for removal
- GrabCut Algorithm: Interactive foreground extraction
- Batch Processing: Process multiple images
- Transparency Output: Export with alpha channel
- Background Replacement: Replace with color or image
Quick Start
from background_remover import BackgroundRemover
remover = BackgroundRemover()
# Simple removal
remover.load("photo.jpg")
remover.remove_background()
remover.save("photo_transparent.png")
# Remove specific color
remover.load("product.jpg")
remover.remove_color((255, 255, 255), tolerance=30) # Remove white
remover.save("product_clean.png")
# Replace background
remover.load("portrait.jpg")
remover.remove_background()
remover.replace_background(color=(0, 120, 255)) # Blue background
remover.save("portrait_blue.png")
CLI Usage
# Remove background (auto-detect)
python background_remover.py --input photo.jpg --output result.png
# Remove specific color
python background_remover.py --input image.jpg --color "255,255,255" --tolerance 30 -o clean.png
# Use GrabCut method
python background_remover.py --input photo.jpg --method grabcut -o result.png
# Replace background with color
python background_remover.py --input photo.jpg --replace-color "0,120,255" -o result.png
# Replace background with image
python background_remover.py --input photo.jpg --replace-image bg.jpg -o result.png
# Batch process
python background_remover.py --batch input_folder/ --output-dir output/ --method edge
API Reference
BackgroundRemover Class
class BackgroundRemover:
def __init__(self)
# Loading
def load(self, filepath: str) -> 'BackgroundRemover'
def load_array(self, array: np.ndarray) -> 'BackgroundRemover'
# Removal Methods
def remove_background(self, method: str = "auto") -> 'BackgroundRemover'
def remove_color(self, color: Tuple, tolerance: int = 20) -> 'BackgroundRemover'
def remove_edges(self, threshold: int = 50) -> 'BackgroundRemover'
def grabcut(self, rect: Tuple = None, iterations: int = 5) -> 'BackgroundRemover'
# Background Operations
def replace_background(self, color: Tuple = None, image: str = None) -> 'BackgroundRemover'
def add_shadow(self, offset: Tuple = (5, 5), blur: int = 10) -> 'BackgroundRemover'
# Refinement
def refine_edges(self, feather: int = 2) -> 'BackgroundRemover'
def expand_mask(self, pixels: int = 2) -> 'BackgroundRemover'
def contract_mask(self, pixels: int = 2) -> 'BackgroundRemover'
# Output
def save(self, filepath: str, quality: int = 95) -> str
def get_image(self) -> Image
def get_mask(self) -> Image
# Batch Processing
def batch_process(self, input_dir: str, output_dir: str,
method: str = "auto") -> List[str]
Removal Methods
Auto Detection
# Automatically choose best method
remover.remove_background(method="auto")
Color-Based Removal
# Remove white background
remover.remove_color((255, 255, 255), tolerance=30)
# Remove green screen
remover.remove_color((0, 255, 0), tolerance=50)
# Remove any solid color
remover.remove_color((200, 200, 200), tolerance=40)
Edge Detection
# Use edge detection to find subject
remover.remove_edges(threshold=50)
GrabCut (OpenCV)
# Full image GrabCut
remover.grabcut(iterations=5)
# With bounding rectangle hint
remover.grabcut(rect=(50, 50, 400, 300), iterations=10)
Background Replacement
Solid Color
remover.remove_background()
remover.replace_background(color=(255, 255, 255)) # White
remover.replace_background(color=(0, 0, 0)) # Black
remover.replace_background(color=(135, 206, 235)) # Sky blue
Image Background
remover.remove_background()
remover.replace_background(image="office_bg.jpg")
Transparent (Default)
remover.remove_background()
remover.save("transparent.png") # PNG preserves alpha
Edge Refinement
# Soften edges with feathering
remover.refine_edges(feather=3)
# Expand mask to include more area
remover.expand_mask(pixels=2)
# Contract mask for tighter crop
remover.contract_mask(pixels=2)
Example Workflows
Product Photography
remover = BackgroundRemover()
# Remove white studio background
remover.load("product_photo.jpg")
remover.remove_color((255, 255, 255), tolerance=25)
remover.refine_edges(feather=2)
remover.save("product_transparent.png")
Portrait Editing
remover = BackgroundRemover()
# Remove background from portrait
remover.load("portrait.jpg")
remover.grabcut(iterations=8)
remover.refine_edges(feather=3)
# Add professional background
remover.replace_background(color=(220, 220, 220))
remover.add_shadow(offset=(5, 5), blur=15)
remover.save("portrait_professional.jpg")
Green Screen Removal
remover = BackgroundRemover()
remover.load("greenscreen_video_frame.jpg")
remover.remove_color((0, 255, 0), tolerance=60)
remover.replace_background(image="virtual_bg.jpg")
remover.save("composited.jpg")
Batch Processing
remover = BackgroundRemover()
processed = remover.batch_process(
input_dir="product_photos/",
output_dir="processed/",
method="color",
color=(255, 255, 255),
tolerance=30
)
print(f"Processed {len(processed)} images")
Output Formats
- PNG: Preserves transparency (recommended)
- WEBP: Smaller file, supports alpha
- JPEG: No transparency (use with replace_background)
Tips for Best Results
- White/Solid Backgrounds: Use
remove_color()method - Complex Backgrounds: Use
grabcut()method - High Contrast Subjects: Edge detection works well
- Portraits: GrabCut with edge refinement
- Product Photos: Color removal with feathering
Limitations
- Best results with high contrast between subject and background
- Complex hair/fur edges may need manual touch-up
- Transparent or semi-transparent subjects are challenging
- Very busy backgrounds may require manual assistance
Dependencies
- pillow>=10.0.0
- opencv-python>=4.8.0
- numpy>=1.24.0
- scikit-image>=0.21.0
How can the creator link this skill?
Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.
<a href="https://skillzs.dev/skills/dkyazzentwatwa/chatgpt-skills/background-remover">View background-remover on skillZs</a>