sam-segmentation

Use SAM (Segment Anything Model) to remove image backgrounds and extract foreground subjects as transparent PNGs. Use when users want to remove backgrounds, cut out objects, extract foreground subjects, or perform image segmentation.

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "sam-segmentation" with this command: npx skills add scikkk/sam

SAM Background Removal

Extract foreground subjects from images using Meta's Segment Anything Model, outputting transparent PNGs.

Quick Start

python3 scripts/segment.py <input_image> <output.png>

Defaults to the image center as the foreground hint — works well for portraits and product shots where the subject is centered.

Parameters

ParamDescriptionDefault
inputInput image pathrequired
outputOutput PNG path (single mode) or directory (--all mode)required
--modelModel size: vit_b (fast) · vit_l (medium) · vit_h (best quality)vit_h
--checkpointLocal checkpoint path; auto-downloaded if omittedauto
--pointsForeground hint points as x,y, multiple allowedcenter
--allGrid-sweep mode: extract all distinct elementsoff
--gridGrid density for --all; 16 means 16×16=256 probe points16
--iou-threshMinimum predicted IoU to accept a mask (--all)0.88
--min-areaMinimum mask area as fraction of image (--all)0.001

Examples

# Basic background removal (auto-downloads vit_h ~2.5GB)
python3 scripts/segment.py photo.jpg output.png

# Specify hint point when subject is off-center
python3 scripts/segment.py photo.jpg output.png --points 320,240

# Multiple hints with lightweight model
python3 scripts/segment.py photo.jpg output.png --model vit_b --points 320,240 400,300

# Extract all elements (one PNG per element)
python3 scripts/segment.py photo.jpg ./elements/ --all

# Denser grid to capture small objects
python3 scripts/segment.py photo.jpg ./elements/ --all --grid 32

# Use a local checkpoint
python3 scripts/segment.py photo.jpg output.png --checkpoint /path/to/sam_vit_h_4b8939.pth

Dependencies

segment_anything is auto-installed on first run, or install manually:

pip install git+https://github.com/facebookresearch/segment-anything.git
pip install pillow numpy torch torchvision

Workflow

  1. User provides image path
  2. Ask if hint points are needed (when subject is off-center)
  3. Run script; checkpoint auto-downloads on first use to ~/.cache/sam/
  4. Output transparent-background PNG

Model Selection

ModelSizeSpeedQuality
vit_b~375 MBfastestgood
vit_l~1.25 GBmediumbetter
vit_h~2.5 GBslowerbest

CUDA is used automatically when a GPU is available.

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

Wechat Mp Writer

WeChat Official Account (公众号) content writer with article formatting, headline optimization, and engagement tips. Use when you need to write WeChat articles,...

Registry SourceRecently Updated
General

OpenClaw EverMemory Installer

Use this skill when installing, upgrading, verifying, or publishing the EverMemory OpenClaw plugin and its companion skill, including local path install, npm...

Registry SourceRecently Updated
General

Ip Advisor

知识产权顾问。专利、版权、商业秘密、注册流程、保护策略。IP advisor for patents, copyrights, trade secrets. 知识产权、专利、版权。

Registry SourceRecently Updated
1950ckchzh
General

炒股大师模拟器

炒股大师模拟器 | 股市模拟交易练习 | A股/港股/美股投资学习 | 化身文主任/股神老徐/炒股养家/孙宇晨等各位大师学习投资思路 | 多智能体股票讨论群

Registry SourceRecently Updated