mcpField
I
image-remove-background

image-remove-background

github.com/agntswrm创意与媒体6205 次安装34 周前更新
代码仓库

关于 image-remove-background

image-remove-background 是用于去除图像背景的命令行技能,输出带透明背景的主体图像。它支持本地 CPU 处理及 fal、replicate 服务商。

主要功能

  1. 01去除图像背景并保留主体
  2. 02支持本地文件或 URL 输入
  3. 03可选择 local、fal、replicate
  4. 04支持指定输出路径
  5. 05fal 支持设置输出分辨率

适用场景

  1. 01为肖像图像创建透明背景
  2. 02处理本地图像或网络图像
  3. 03通过 fal 按指定分辨率处理图像

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/agntswrm/agent-media --skill image-remove-background

安装后在 Claude Code 中输入/image-remove-background确认已加载。

详细介绍

移除图像背景

移除图像背景,仅保留带透明度的前景主体。

命令

npx agent-media@latest image remove-background --in <path> [options]

输入

选项必填描述
--in是输入文件路径或 URL
--out否输出路径、文件名或目录(默认:./)
--provider否要使用的提供方(local、fal、replicate)
--resolution否输出分辨率(例如:"2048x2048")。fal Dynamic 模型支持此选项。

输出

返回包含处理后图像路径的 JSON 对象:

{
  "ok": true,
  "media_type": "image",
  "action": "remove-background",
  "provider": "fal",
  "output_path": "nobg_123_abc.png",
  "mime": "image/png",
  "bytes": 34567
}

示例

移除本地文件的背景:

npx agent-media@latest image remove-background --in portrait.jpg

使用指定提供方移除背景:

npx agent-media@latest image remove-background --in portrait.jpg --provider replicate

使用完整分辨率移除背景(fal Dynamic 模型):

npx agent-media@latest image remove-background --in portrait.jpg --provider fal --resolution 2048x2048

提供方

local

使用 Transformers.js 在本地通过 CPU 运行,无需 API 密钥。

  • 使用 Xenova/modnet 模型
  • 首次使用时下载模型(约 25MB)
  • 你可能会看到 mutex lock failed 错误——请忽略;如果 "ok": true,则输出正确
npx agent-media@latest image remove-background --in portrait.jpg --provider local
fal
  • 需要 FAL_API_KEY
  • 使用带有 General Use (Dynamic) 变体的 birefnet/v2 模型
  • 支持 --resolution 选项(例如:"2048x2048"),以输入图像的完整分辨率进行处理
replicate
  • 需要 REPLICATE_API_TOKEN
  • 使用 birefnet 模型

评论

支持 Markdown