什么是抠图?
抠图(Image Matting)是不需要绿幕摄影等特别的准备,从普通的照片或图像中 分离前景和背景 的任务。
所谓的“背景去除服务”大都是以这个抠图技术为基础的。
能够尽量自然地抠出像头发这样细微的部分,是抠图的目标。它生成的不只是单纯的二值蒙版(只有黑白),而是包含被称为 Alpha Matte 的半透明信息的蒙版。
BiRefNet
BiRefNet 是前景提取用的模型家族,是专注于背景去除・Matte 生成的高精度模型。
既轻量又高性能,所以如果是抠图的话选 BiRefNet 肯定没错。

{
"id": "a0b2be7a-c2e9-4cc2-8fbf-f95d36715b31",
"revision": 0,
"last_node_id": 5,
"last_link_id": 2,
"nodes": [
{
"id": 3,
"type": "LoadImage",
"pos": [
250.89995741736612,
347.14664696554024
],
"size": [
287.5053580719291,
450.10539697479544
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
1
]
},
{
"name": "MASK",
"type": "MASK",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.76",
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"download (2).jpg",
"image"
]
},
{
"id": 5,
"type": "PreviewImage",
"pos": [
958.2898495890004,
347.14664696554024
],
"size": [
303.8010543986795,
451.8862758316757
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 2
}
],
"outputs": [],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.76",
"Node name for S&R": "PreviewImage"
},
"widgets_values": []
},
{
"id": 2,
"type": "BiRefNetRMBG",
"pos": [
578.3475825391478,
347.14664696554024
],
"size": [
340,
254
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [
{
"name": "image",
"type": "IMAGE",
"link": 1
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
2
]
},
{
"name": "MASK",
"type": "MASK",
"links": null
},
{
"name": "MASK_IMAGE",
"type": "IMAGE",
"links": null
}
],
"properties": {
"cnr_id": "comfyui-rmbg",
"ver": "2.9.4",
"Node name for S&R": "BiRefNetRMBG"
},
"widgets_values": [
"BiRefNet-general",
0,
0,
false,
false,
"Color",
"#00ff00"
],
"color": "#232",
"bgcolor": "#353"
}
],
"links": [
[
1,
3,
0,
2,
0,
"IMAGE"
],
[
2,
2,
0,
5,
0,
"IMAGE"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 0.8390545288824066,
"offset": [
331.78619236058324,
-82.67581074490566
]
},
"frontendVersion": "1.34.3",
"VHS_latentpreview": false,
"VHS_latentpreviewrate": 0,
"VHS_MetadataImage": true,
"VHS_KeepIntermediate": true
},
"version": 0.4
}
有几个派生模型,请先试用 general。它支持人物・物体・动物等广泛的对象。
SDMatte
SDMatte 是利用了 Stable Diffusion 知识的抠图模型。

{
"id": "65034a86-af32-415a-b5ca-ce79977a3ce2",
"revision": 0,
"last_node_id": 5,
"last_link_id": 5,
"nodes": [
{
"id": 3,
"type": "LoadImage",
"pos": [
511.5893977429975,
526.5473017534738
],
"size": [
235.54080296334837,
424.26372416944594
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
1,
5
]
},
{
"name": "MASK",
"type": "MASK",
"links": [
4
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.76",
"Node name for S&R": "LoadImage",
"image": "clipspace/clipspace-painted-masked-1764669141236.png [input]"
},
"widgets_values": [
"clipspace/clipspace-painted-masked-1764669141236.png [input]",
"image"
]
},
{
"id": 4,
"type": "PreviewImage",
"pos": [
1143.6230517411107,
526.5473017534738
],
"size": [
298.091539559186,
440.3547948789003
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 2
}
],
"outputs": [],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.76",
"Node name for S&R": "PreviewImage"
},
"widgets_values": []
},
{
"id": 5,
"type": "PreviewImage",
"pos": [
795.3766262237283,
184.33068885193995
],
"size": [
210,
281.3969843170496
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 5
}
],
"outputs": [],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.3.76",
"Node name for S&R": "PreviewImage"
},
"widgets_values": []
},
{
"id": 1,
"type": "AILab_SDMatte",
"pos": [
795.3766262237283,
526.5473017534738
],
"size": [
300,
350
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"name": "image",
"type": "IMAGE",
"link": 1
},
{
"name": "mask",
"shape": 7,
"type": "MASK",
"link": 4
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
2
]
},
{
"name": "MASK",
"type": "MASK",
"links": null
},
{
"name": "MASK_IMAGE",
"type": "IMAGE",
"links": null
}
],
"properties": {
"cnr_id": "comfyui-rmbg",
"ver": "2.9.4",
"Node name for S&R": "AILab_SDMatte"
},
"widgets_values": [
"SDMatte_plus",
"Auto",
1024,
true,
true,
0.9,
0,
0,
false,
"Color",
"#000000"
],
"color": "#232",
"bgcolor": "#353"
}
],
"links": [
[
1,
3,
0,
1,
0,
"IMAGE"
],
[
2,
1,
0,
4,
0,
"IMAGE"
],
[
4,
3,
1,
1,
1,
"MASK"
],
[
5,
3,
0,
5,
0,
"IMAGE"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 0.8390545288824083,
"offset": [
-286.44854409686263,
-27.12344147084978
]
},
"frontendVersion": "1.34.3",
"VHS_latentpreview": false,
"VHS_latentpreviewrate": 0,
"VHS_MetadataImage": true,
"VHS_KeepIntermediate": true
},
"version": 0.4
}
和 BiRefNet 一样可以进行前景抠图,但特征是对于玻璃瓶・液体・薄布等 透视可见的东西 也能在一定程度上处理。
作为基于扩散的命运,计算成本很高,但如果是想抠出透明・半透明的客体、发梢这样极细的东西时,请尝试一下。