关于 background-removal
background-removal 是通过 each::sense API 去除或替换图像背景的技能,API 会根据请求选择模型。它提供请求示例,以及边缘、光线和阴影处理建议。
主要功能
- 01按请求选择图像编辑模型
- 02去除或替换背景
- 03输出透明或纯色背景
- 04使用参考图合成场景
- 05流式与批处理示例
- 06边缘、光线和阴影提示词
适用场景
- 01制作透明背景的商品抠图
- 02为肖像替换背景
- 03将主体合成到参考场景
- 04批量处理多张商品图片
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ awesome-genmedia/ skills --skill background-removal安装后在 Claude Code 中输入/background-removal确认已加载。
详细介绍
背景移除
使用 each::sense 通过像素级精准的边缘检测移除图像背景——这款智能 AI Agent 会自动为你的请求选择最佳模型。
快速开始
需要 each::labs API 密钥。请在 eachlabs.ai 获取。
使用 curl
curl -X POST https://eachsense-agent.core.eachlabs.run/v1/chat/completions \
-H "Content-Type: application/json" \
-H "X-API-Key: $EACHLABS_API_KEY" \
-d '{
"messages": [{"role": "user", "content": [
{"type": "text", "text": "Remove the background from this image completely. Return the subject on a transparent background with clean edges."},
{"type": "image_url", "image_url": {"url": "https://example.com/product-photo.jpg"}}
]
}
],
"stream": false
}'
使用 Python(OpenAI SDK)
from openai import OpenAI
client = OpenAI(
api_key="YOUR_EACHLABS_API_KEY",
base_url="https://eachsense-agent.core.eachlabs.run/v1"
)
response = client.chat.completions.create(
model="eachsense/beta",
messages=[{"role": "user", "content": "Remove the background from this image completely. Return the subject on a transparent background with clean edges."}],
# Images are included in the message content array above
)
print(response.choices[0].message.content)
使用参考图像
curl -X POST https://eachsense-agent.core.eachlabs.run/v1/chat/completions \
-H "Content-Type: application/json" \
-H "X-API-Key: $EACHLABS_API_KEY" \
-d '{
"messages": [{"role": "user", "content": [
{"type": "text", "text": "Remove the background from the first image and place the subject onto the scene shown in the second image. Match lighting and scale naturally."},
{"type": "image_url", "image_url": {"url": "https://example.com/person.jpg"}},
{"type": "image_url", "image_url": {"url": "https://example.com/new-background.jpg"}}
]
}
],
"stream": false
}'
图像会使用 OpenAI 多模态内容格式放在消息中发送。每个请求最多可包含 4 张图像。
流式传输
将 "stream": true 设为实时接收 SSE 响应,或将 "stream": false 设为在单个响应中获取完整结果。流式传输适合在 UI 中显示进度;非流式传输则更适合脚本和自动化。
可用模型
| 模型 | 优势 | 最适用于 |
|---|---|---|
| eachlabs-bg-remover-v1 | 精准的边缘检测、头发/毛发处理、透明输出 | 干净的抠图、产品照片、人像 |
| flux-2-edit | 使用自然语言替换背景 | 更换为特定的新背景 |
| flux-fill-pro | 移除背景后的图像修补 | 用新内容填充背景区域 |
对于纯移除任务,each::sense 会选择 eachlabs-bg-remover-v1;如果请求替换背景,则会选择 flux-2-edit。
使用场景
| 使用场景 | 指令 | 输出 |
|---|---|---|
| 透明 PNG | “完全移除背景” | 主体置于透明背景上 |
| 白色背景 | “移除背景,替换为纯白色” | 干净的电商商品列表图 |
| 纯色背景 | “将背景替换为品牌蓝色(#2563EB)” | 品牌营销素材 |
| 渐变背景 | “替换为柔和的灰白渐变” | 专业人像照 |
| 更换环境 | “将主体放在日落时分的热带海滩上” | 生活方式合成图 |
| 影棚背景 | “替换为无缝灰色影棚背景” | 专业产品照 |
提示词技巧
干净地移除背景
"Remove the background completely. Keep edges sharp and clean,
especially around hair and fine details. Transparent background."
替换背景
"Remove the current background and replace it with [description].
Match the lighting direction from the original photo.
Keep a natural contact shadow beneath the subject."
阴影处理
控制阴影的处理方式:
"Remove background but keep the natural shadow beneath the product"
"Remove background and all shadows for a clean cutout"
"Remove background, add a soft artificial drop shadow on white"
边缘质量
指定所需的边缘处理方式:
"Ensure hair edges are soft and natural, not hard-cut"
"Keep crisp edges around the product with no background bleed"
"Apply a very slight feather on the edges for smooth compositing"
示例
电商产品抠图
curl -X POST https://eachsense-agent.core.eachlabs.run/v1/chat/completions \
-H "Content-Type: application/json" \
-H "X-API-Key: $EACHLABS_API_KEY" \
-d '{
"messages": [{"role": "user", "content": [
{"type": "text", "text": "Remove the background from this product photo and replace it with a pure white (#FFFFFF) background. Keep a soft, natural drop shadow beneath the product for a floating effect. Crisp edges with no background artifacts."},
{"type": "image_url", "image_url": {"url": "https://example.com/sneaker-on-table.jpg"}}
]
}
],
"stream": false
}'
专业人像照
curl -X POST https://eachsense-agent.core.eachlabs.run/v1/chat/completions \
-H "Content-Type: application/json" \
-H "X-API-Key: $EACHLABS_API_KEY" \
-d '{
"messages": [{"role": "user", "content": [
{"type": "text", "text": "Remove the background from this portrait photo. Replace with a smooth, soft-focus dark gray gradient that is lighter in the center. Keep hair edges natural and wispy, not hard-cut. Professional headshot quality."},
{"type": "image_url", "image_url": {"url": "https://example.com/office-portrait.jpg"}}
]
}
],
"stream": false
}'
用于设计的透明素材
curl -X POST https://eachsense-agent.core.eachlabs.run/v1/chat/completions \
-H "Content-Type: application/json" \
-H "X-API-Key: $EACHLABS_API_KEY" \
-d '{
"messages": [{"role": "user", "content": [
{"type": "text", "text": "Remove the background from this image entirely. Output a transparent PNG with no background at all. Clean edges suitable for layering in a design tool like Figma or Photoshop. Remove all shadows."},
{"type": "image_url", "image_url": {"url": "https://example.com/plant-photo.jpg"}}
]
}
],
"stream": false
}'
生活方式合成图
curl -X POST https://eachsense-agent.core.eachlabs.run/v1/chat/completions \
-H "Content-Type: application/json" \
-H "X-API-Key: $EACHLABS_API_KEY" \
-d '{
"messages": [{"role": "user", "content": [
{"type": "text", "text": "Remove the background and place this person on a sunlit rooftop terrace overlooking a Mediterranean coastal city. Match the warm afternoon lighting from the original photo. The person should look naturally placed in the scene with correct scale and perspective."},
{"type": "image_url", "image_url": {"url": "https://example.com/standing-person.jpg"}}
]
}
],
"stream": false
}'
社交媒体品牌帖子
curl -X POST https://eachsense-agent.core.eachlabs.run/v1/chat/completions \
-H "Content-Type: application/json" \
-H "X-API-Key: $EACHLABS_API_KEY" \
-d '{
"messages": [{"role": "user", "content": [
{"type": "text", "text": "Remove the background from this photo and replace it with a bold coral-to-magenta gradient going from bottom-left to top-right. Keep the subject sharp with clean edges. This is for an Instagram post, so make it vibrant and eye-catching."},
{"type": "image_url", "image_url": {"url": "https://example.com/influencer-photo.jpg"}}
]
}
],
"stream": false
}'
批量处理
# Remove backgrounds from multiple product photos
PRODUCTS=(
"https://example.com/product-1.jpg"
"https://example.com/product-2.jpg"
"https://example.com/product-3.jpg"
"https://example.com/product-4.jpg"
)
for URL in "${PRODUCTS[@]}"; do
curl -X POST https://eachsense-agent.core.eachlabs.run/v1/chat/completions \
-H "Content-Type: application/json" \
-H "X-API-Key: $EACHLABS_API_KEY" \
-d "{
\"messages\": [{\"role\": \"user\", \"content\": \"Remove the background. Replace with pure white. Keep a soft natural shadow. Clean product cutout.\"}],
\"image_urls\": [\"$URL\"],
\"stream\": false
}"
echo "---"
done
主体类型与技巧
| 主体 | 难点 | 技巧 |
|---|---|---|
| 人物(头发) | 细小的发丝 | “让头发边缘保持柔和自然” |
| 宠物(毛发) | 蓬松的边缘 | “保留边缘处的毛发细节” |
| 产品(硬边缘) | 反光、阴影 | “保持边缘清晰,并处理反光” |
| 植物(叶片) | 复杂的轮廓 | “保留叶片细节和间隙” |
| 透明物体 | 玻璃、瓶子 | “处理透明/半透明区域” |
| 复杂场景 | 多个主体 | “只分离中心的主要主体” |
常见问题
- 未指定要保留的内容:“移除背景”是不错的指令;有需要时,“移除背景,但保留产品放置的桌子”会更好。
- 期望自动匹配颜色:替换背景时,务必提及“匹配光线”,以获得自然效果。
- 忽略头发/毛发边缘:默认移除可能会生硬地裁掉精细细节。请明确要求“柔和自然的头发边缘”。
- 未说明阴影处理方式:模型可能会不可预测地保留或移除阴影。请说明你的偏好。
- 颜色与主体相近的繁杂背景更难处理。主体和背景之间的对比度越高,结果越干净。
相关技能
文档
评论
支持 Markdown