image-remove-background

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Image Remove Background

图片背景移除

Removes the background from an image, leaving only the foreground subject with transparency.
移除图片中的背景,仅保留带透明效果的前景主体。

Command

命令

bash
agent-media image remove-background --in <path> [options]
bash
agent-media image remove-background --in <path> [options]

Inputs

输入参数

OptionRequiredDescription
--in
YesInput file path or URL
--out
NoOutput path, filename or directory (default: ./)
--provider
NoProvider to use (local, fal, replicate)
选项是否必填描述
--in
输入文件路径或URL
--out
输出路径、文件名或目录(默认值:./)
--provider
使用的服务提供商(local, fal, replicate)

Output

输出结果

Returns a JSON object with the processed image path:
json
{
  "ok": true,
  "media_type": "image",
  "action": "remove-background",
  "provider": "fal",
  "output_path": "nobg_123_abc.png",
  "mime": "image/png",
  "bytes": 34567
}
返回包含处理后图片路径的JSON对象:
json
{
  "ok": true,
  "media_type": "image",
  "action": "remove-background",
  "provider": "fal",
  "output_path": "nobg_123_abc.png",
  "mime": "image/png",
  "bytes": 34567
}

Examples

示例

Remove background from local file:
bash
agent-media image remove-background --in portrait.jpg
Remove background using specific provider:
bash
agent-media image remove-background --in portrait.jpg --provider replicate
从本地文件移除背景:
bash
agent-media image remove-background --in portrait.jpg
使用指定服务提供商移除背景:
bash
agent-media image remove-background --in portrait.jpg --provider replicate

Providers

服务提供商

local

local

Runs locally on CPU using Transformers.js, no API key required.
  • Uses
    Xenova/modnet
    model
  • Models downloaded on first use (~25MB)
  • You may see a
    mutex lock failed
    error — ignore it, the output is correct if
    "ok": true
bash
agent-media image remove-background --in portrait.jpg --provider local
使用Transformers.js在本地CPU运行,无需API密钥。
  • 使用
    Xenova/modnet
    模型
  • 首次使用时会下载模型(约25MB)
  • 可能会出现
    mutex lock failed
    错误——忽略即可,若返回
    "ok": true
    则输出结果正确
bash
agent-media image remove-background --in portrait.jpg --provider local

fal

fal

  • Requires
    FAL_API_KEY
  • Uses
    birefnet/v2
    model
  • 需要
    FAL_API_KEY
  • 使用
    birefnet/v2
    模型

replicate

replicate

  • Requires
    REPLICATE_API_TOKEN
  • Uses
    birefnet
    model
  • 需要
    REPLICATE_API_TOKEN
  • 使用
    birefnet
    模型