DeepAI 图像编辑、超分、色彩化、背景移除 API 详解
概述
DeepAI 的图像编辑类 API 是同一个 HTTP 调用模式的不同端点——每个端点处理一种特定的编辑任务,调用方式完全相同(POST + image 参数 + api-key Header)。
| API 端点 | 功能 | 必选参数 | 可选参数 |
|---|---|---|---|
/api/image-editor | 通用图像编辑(文本驱动) | image + text | 无 |
/api/superresolution | 超分辨率放大 | image | 无 |
/api/colorizer | 黑白照片上色 | image | 无 |
/api/backgroundremover | 背景移除(抠图) | image | 无 |
通用调用模式
所有这些 API 的调用方式都是一样的:
上传方式:URL
import requests
r = requests.post(
"https://api.deepai.org/api/<endpoint>",
data={'image': 'https://example.com/your-image.jpg'},
headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())
上传方式:本地文件
import requests
with open('local-image.jpg', 'rb') as f:
r = requests.post(
"https://api.deepai.org/api/<endpoint>",
files={'image': f},
headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())
上传方式:Base64
import requests, base64
with open('local-image.jpg', 'rb') as f:
b64 = base64.b64encode(f.read()).decode()
r = requests.post(
"https://api.deepai.org/api/<endpoint>",
data={'image': f'data:image/jpeg;base64,{b64}'},
headers={'api-key': 'YOUR_API_KEY'}
)
print(r.json())
推荐:URL 方式最省事(不需要上传文件),但如果你的图片不在公开可访问的 URL 上,用本地文件方式。
1. image-editor(通用图像编辑)
功能
用文字描述修改图像——比如「把天空变红」「加一束花在旁边」「移除右边的人」。
必选参数
| 参数 | 类型 | 说明 |
|---|---|---|
| image | string / file | 待修改的图像 |
| text | string | 你想做什么修改 |
示例
r = requests.post(
"https://api.deepai.org/api/image-editor",
data={
'image': 'https://example.com/photo.jpg',
'text': 'change the sky to beautiful sunset, add a rainbow'
},
headers={'api-key': 'YOUR_API_KEY'}
)
效果
- 色彩调整:效果很好
- 添加元素:好(简单元素)
- 移除元素:中等(可能留痕迹)
- 风格变换:好
2. superresolution(超分辨率)
功能
AI 放大图像,智能填充细节。
必选参数
| 参数 | 类型 | 说明 |
|---|---|---|
| image | string / file | 待放大的图像 |
放大倍数
API 目前默认放大 2×。如果需要 4× 放大,可以把第一次的输出 URL 作为第二次的输入再调用一次。
示例
r = requests.post(
"https://api.deepai.org/api/superresolution",
data={'image': 'https://example.com/small-photo.jpg'},
headers={'api-key': 'YOUR_API_KEY'}
)
3. colorizer(色彩化)
功能
黑白照片上色。
必选参数
| 参数 | 类型 | 说明 |
|---|---|---|
| image | string / file | 黑白照片 |
示例
r = requests.post(
"https://api.deepai.org/api/colorizer",
data={'image': 'https://example.com/bw-photo.jpg'},
headers={'api-key': 'YOUR_API_KEY'}
)
输入建议
- 上传清晰的黑白照片(模糊或破损的先修一下)
- 尽量是 JPG / PNG 格式
- 尺寸不要太大(建议 2048×2048 以下)
4. backgroundremover(背景移除)
功能
一键抠图。
必选参数
| 参数 | 类型 | 说明 |
|---|---|---|
| image | string / file | 待抠图的图像 |
示例
r = requests.post(
"https://api.deepai.org/api/backgroundremover",
data={'image': 'https://example.com/product-photo.jpg'},
headers={'api-key': 'YOUR_API_KEY'}
)
输出格式
返回的是透明背景的 PNG——直接下载就是你要的结果。
配额消耗
这四个 API 共用同一个配额池——每调一次扣 1 次 API 配额,不管是 image-editor 还是 backgroundremover。
| 用户类型 | 配额 | 单次成本 |
|---|---|---|
| 免费注册 | $5 / 100 次 | $0.05 |
| Pro 订阅 | $5 / 500 次 | $0.01 |
返回值格式
所有 API 的返回值都是统一的:
{
"output_url": "https://api.deepai.org/api/...",
"id": "..."
}
下载 output_url 就是处理后的结果图片。
错误处理
和 text2img API 相同——400 / 401 / 403 / 429 / 500 等 HTTP 状态码,加重试机制。
四个 API 的组合使用场景
场景一:电商商品图制作
import requests
API_KEY = 'YOUR_API_KEY'
BASE = 'https://api.deepai.org/api'
headers = {'api-key': API_KEY}
# Step 1: 背景移除(把商品从原背景抠出来)
r1 = requests.post(f'{BASE}/backgroundremover',
data={'image': 'https://example.com/product.jpg'}, headers=headers)
transparent_url = r1.json()['output_url']
# Step 2: 超分辨率(放大到商品图标准尺寸)
r2 = requests.post(f'{BASE}/superresolution',
data={'image': transparent_url}, headers=headers)
upscaled_url = r2.json()['output_url']
# Step 3: 添加白色背景
r3 = requests.post(f'{BASE}/image-editor',
data={'image': upscaled_url, 'text': 'change background to pure white'},
headers=headers)
final_url = r3.json()['output_url']
三步总共扣 3 次 API 配额($0.03–$0.15)。
场景二:老照片修复
- superresolution → 放大变清晰
- colorizer → 变彩色
- image-editor → 用文字提示补细节(可选)
场景三:电商商品图自动化
如果你有大量商品图需要处理,可以写脚本批量调用 backgroundremover API——DeepAI 的 API 没有批量限制,只是单次调用。
和 remove.bg / rembg 等的对比
| 工具 | 价格 | 质量 | 自托管 | 备注 |
|---|---|---|---|---|
| DeepAI backgroundremover | $0.01–$0.05 / 次 | 好 | 否(SaaS) | 含在 API 套件里 |
| remove.bg | $0.20–$0.05 / 次 | 极好 | 否(SaaS) | 业界标杆 |
| rembg | 免费 | 好 | 是(本地) | 开源,需要 GPU |
| Stability AI remove-bg | $0.05 / 次 | 好 | 否(SaaS) | Stability 生态 |
DeepAI 的抠图 API 不是行业最好的——remove.bg 质量最高,rembg 完全免费且自托管。但 DeepAI API 的优势是一个 Key 覆盖多种能力——如果你同时需要文生图、超分、色彩化、抠图,用 DeepAI 一套 API 就搞定,不用分别对接三家。