What is BiRefNet?
BiRefNet is a model used for background removal and matting.
Formally, it is a model for Dichotomous Image Segmentation (DIS), which means splitting an image into foreground and background.
It is not like SAM, where you specify "this point", "this box", or "this object" to create a mask. Instead, it is good at producing high-quality cutout masks from subjects with complex details, such as hair or plants.
Model Download
- birefnet.safetensors (444 MB)
📂ComfyUI/
└── 📂models/
└── 📂background_removal/
└── birefnet.safetensors
workflow
Cut Out the Foreground

{
"id": "32d5b916-1532-435e-8274-bab16b8cce42",
"revision": 0,
"last_node_id": 15,
"last_link_id": 18,
"nodes": [
{
"id": 3,
"type": "LoadBackgroundRemovalModel",
"pos": [
769.3428839311762,
373.2630368921259
],
"size": [
328.627516211709,
58
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "bg_model",
"type": "BACKGROUND_REMOVAL",
"links": [
1
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.26.0",
"Node name for S&R": "LoadBackgroundRemovalModel"
},
"widgets_values": [
"birefnet.safetensors"
],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 1,
"type": "RemoveBackground",
"pos": [
1140.4167084744367,
373.2630368921259
],
"size": [
204.705078125,
46
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"name": "bg_removal_model",
"type": "BACKGROUND_REMOVAL",
"link": 1
},
{
"name": "image",
"type": "IMAGE",
"link": 8
}
],
"outputs": [
{
"name": "mask",
"type": "MASK",
"links": [
3,
13
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.26.0",
"Node name for S&R": "RemoveBackground"
},
"widgets_values": [],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 10,
"type": "InvertMask",
"pos": [
1387.568094930988,
373.2630368921259
],
"size": [
140,
26
],
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "mask",
"type": "MASK",
"link": 13
}
],
"outputs": [
{
"name": "MASK",
"type": "MASK",
"links": [
15
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.26.0",
"Node name for S&R": "InvertMask"
},
"widgets_values": [],
"color": "#432",
"bgcolor": "#653"
},
{
"id": 4,
"type": "MaskPreview",
"pos": [
1387.568094930988,
617.9104524429572
],
"size": [
261.7862348244132,
283.74516954429964
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"name": "mask",
"type": "MASK",
"link": 3
}
],
"outputs": [],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.26.0",
"Node name for S&R": "MaskPreview"
},
"widgets_values": []
},
{
"id": 2,
"type": "LoadImage",
"pos": [
769.3428839311762,
494.9638574769056
],
"size": [
328.627516211709,
406.6917645103512
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
8,
16
]
},
{
"name": "MASK",
"type": "MASK",
"links": []
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.26.0",
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"normal02_input.jpg",
"image"
]
},
{
"id": 11,
"type": "JoinImageWithAlpha",
"pos": [
1587.4157037841544,
494.9638574769056
],
"size": [
216.6609912109374,
46
],
"flags": {},
"order": 5,
"mode": 0,
"inputs": [
{
"name": "image",
"type": "IMAGE",
"link": 16
},
{
"name": "alpha",
"type": "MASK",
"link": 15
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
18
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.26.0",
"Node name for S&R": "JoinImageWithAlpha"
},
"widgets_values": [],
"color": "#432",
"bgcolor": "#653"
},
{
"id": 15,
"type": "SaveImage",
"pos": [
1841.5916728163381,
494.9638574769056
],
"size": [
303.0471535866202,
354.2881776680789
],
"flags": {},
"order": 6,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 18
}
],
"outputs": [
{
"name": "images",
"type": "IMAGE",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.26.0"
},
"widgets_values": [
"ComfyUI"
]
}
],
"links": [
[
1,
3,
0,
1,
0,
"BACKGROUND_REMOVAL"
],
[
3,
1,
0,
4,
0,
"MASK"
],
[
8,
2,
0,
1,
1,
"IMAGE"
],
[
13,
1,
0,
10,
0,
"MASK"
],
[
15,
10,
0,
11,
1,
"MASK"
],
[
16,
2,
0,
11,
0,
"IMAGE"
],
[
18,
11,
0,
15,
0,
"IMAGE"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 1,
"offset": [
-585.8257424834793,
-221.4257217325228
]
},
"frontendVersion": "1.45.19"
},
"version": 0.4
}
- Use
Load Background Removal Modelto loadbirefnet.safetensors. - Input the image and model into
Remove Backgroundto output a background-removalMASK. - Use
Join Image with Alphawhen you want an image with a transparent background.- If you use the mask as-is, the foreground becomes transparent, so insert
Invert Maskfirst.
- If you use the mask as-is, the foreground becomes transparent, so insert
Fill the Background
The workflow above makes the background transparent, but for preprocessing in image generation or analysis, it is often easier to fill the background with a solid color.

{
"id": "32d5b916-1532-435e-8274-bab16b8cce42",
"revision": 0,
"last_node_id": 13,
"last_link_id": 20,
"nodes": [
{
"id": 3,
"type": "LoadBackgroundRemovalModel",
"pos": [
776.2984792746487,
215.5777412691436
],
"size": [
325.9727446183857,
58
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "bg_model",
"type": "BACKGROUND_REMOVAL",
"links": [
1
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.26.0",
"Node name for S&R": "LoadBackgroundRemovalModel"
},
"widgets_values": [
"birefnet.safetensors"
],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 1,
"type": "RemoveBackground",
"pos": [
1145.3690790242017,
215.5777412691436
],
"size": [
204.705078125,
46
],
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "bg_removal_model",
"type": "BACKGROUND_REMOVAL",
"link": 1
},
{
"name": "image",
"type": "IMAGE",
"link": 8
}
],
"outputs": [
{
"name": "mask",
"type": "MASK",
"links": [
15
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.26.0",
"Node name for S&R": "RemoveBackground"
},
"widgets_values": [],
"color": "#232",
"bgcolor": "#353"
},
{
"id": 11,
"type": "InvertMask",
"pos": [
1393.172012280369,
215.5777412691436
],
"size": [
140,
26
],
"flags": {},
"order": 5,
"mode": 0,
"inputs": [
{
"name": "mask",
"type": "MASK",
"link": 15
}
],
"outputs": [
{
"name": "MASK",
"type": "MASK",
"links": [
16
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.26.0",
"Node name for S&R": "InvertMask"
},
"widgets_values": [],
"color": "#432",
"bgcolor": "#653"
},
{
"id": 12,
"type": "ColorToRGBInt",
"pos": [
1262.8057138281881,
426.71661130361684
],
"size": [
270,
78
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "rgb_int",
"type": "INT",
"links": [
19
]
},
{
"name": "hex",
"type": "COLOR",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.26.0",
"Node name for S&R": "ColorToRGBInt"
},
"widgets_values": [
"#ffffff"
],
"color": "#432",
"bgcolor": "#653"
},
{
"id": 10,
"type": "EmptyImage",
"pos": [
1262.8055334741948,
555.658608688232
],
"size": [
270,
130
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"name": "color",
"type": "INT",
"widget": {
"name": "color"
},
"link": 19
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
18
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.26.0",
"Node name for S&R": "EmptyImage"
},
"widgets_values": [
1024,
1024,
1,
0
],
"color": "#432",
"bgcolor": "#653"
},
{
"id": 2,
"type": "LoadImage",
"pos": [
775.1632258740977,
335.574967141765
],
"size": [
325.5056205715746,
459.13681582045564
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
8,
17
]
},
{
"name": "MASK",
"type": "MASK",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.26.0",
"Node name for S&R": "LoadImage"
},
"widgets_values": [
"depth03_input.jpg",
"image"
]
},
{
"id": 8,
"type": "ImageCompositeMasked",
"pos": [
1597.768975382267,
332.6964371281348
],
"size": [
271.64609375,
146
],
"flags": {},
"order": 6,
"mode": 0,
"inputs": [
{
"name": "destination",
"type": "IMAGE",
"link": 17
},
{
"name": "source",
"type": "IMAGE",
"link": 18
},
{
"name": "mask",
"shape": 7,
"type": "MASK",
"link": 16
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": [
20
]
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.26.0",
"Node name for S&R": "ImageCompositeMasked"
},
"widgets_values": [
0,
0,
true
],
"color": "#432",
"bgcolor": "#653"
},
{
"id": 13,
"type": "SaveImage",
"pos": [
1904.5789033233184,
332.6964371281348
],
"size": [
360.75008862304685,
495.060003692627
],
"flags": {},
"order": 7,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": 20
}
],
"outputs": [
{
"name": "images",
"type": "IMAGE",
"links": null
}
],
"properties": {
"cnr_id": "comfy-core",
"ver": "0.26.0"
},
"widgets_values": [
"ComfyUI"
]
}
],
"links": [
[
1,
3,
0,
1,
0,
"BACKGROUND_REMOVAL"
],
[
8,
2,
0,
1,
1,
"IMAGE"
],
[
15,
1,
0,
11,
0,
"MASK"
],
[
16,
11,
0,
8,
2,
"MASK"
],
[
17,
2,
0,
8,
0,
"IMAGE"
],
[
18,
10,
0,
8,
1,
"IMAGE"
],
[
19,
12,
0,
10,
0,
"INT"
],
[
20,
8,
0,
13,
0,
"IMAGE"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 0.7513148009015778,
"offset": [
-431.4889771758615,
-4.5243700184477955
]
},
"frontendVersion": "1.45.19",
"VHS_latentpreview": false,
"VHS_latentpreviewrate": 0,
"VHS_MetadataImage": true,
"VHS_KeepIntermediate": true
},
"version": 0.4
}
- Input the original image, inverted mask, and solid-color image into
Image Composite Masked. - Only the masked background area is replaced with the solid-color image.
- See Layer Composite for details.