Image Editing with ComfyUI Standard Nodes + α! How to Use BiRefNet, Depth-Anything-V3, and Lama Remover [Image Generation AI]
Introduction
Hello, I'm Kimama / Easygoing.
In this video, I will introduce image editing using ComfyUI standard nodes with a few custom nodes added.

SAM 3.1 is a general-purpose model
Last time, I introduced background removal using the SAM 3.1 model.
The SAM 3.1 model is a general-purpose model that can detect anything if you provide text input.
How to use the SAM 3.1 model
General-purpose models are very convenient because they can recognize any subject, but when limited to the purpose of foreground and background segmentation, using a specialized model provides better accuracy.
So first, I will introduce how to use the BiRefNet model, which can be used with ComfyUI standard nodes.
BiRefNet is a specialized model for background removal!
BiRefNet is an AI model specialized for binary image segmentation (separating the foreground from the background).
There are several types in the BiRefNet model series, but the orthodox BiRefNet model is officially distributed by Comfy Org , so we will use that one this time.
Workflow

Model
background_removal: birefnet.safetensors
Installation location for birefnet.safetensors
ComfyUI\models\background_removal (create a new folder)
Custom Nodes

Background removal with BiRefNet
Now, let's compare background removal between SAM 3.1 and BiRefNet.
Input image

Background removal with SAM 3.1

Background removal with BiRefNet

Compared to SAM 3.1, you can see that BiRefNet's background removal accurately classifies details such as hair.
BiRefNet boundaries are jagged
Next, let's zoom in further on the boundary area of BiRefNet.
Enlarged view of BiRefNet

When you zoom in on the BiRefNet detection, the thin hair parts appear jagged and look broken.
In the ComfyUI implementation, the BiRefNet model processes at a fixed resolution of 1024 x 1024, so for high-resolution illustrations, the resolution is insufficient, resulting in this appearance.
Include semi-transparent parts in the mask area
Now, to ensure the hair is reliably included in the foreground without being cut off, I will include semi-transparent parts determined by BiRefNet between the foreground and background entirely in the foreground.
Connect the mask created by BiRefNet to the Threshold Mask node and set the Threshold to the minimum value of 0.01.
Threshold Mask = 0.01

Compared to before, the hair is now firmly included in the foreground, but now thin background has crept into the boundary area.
Adjust the mask area with the Mask Refine node!
From here, I will further adjust the mask area using a custom node.
ComfyUI-AutoMask's Mask Refine node is a custom node that compares the original illustration with the mask using a method called pymatting to adjust the mask area.
Adjusting boundaries with the Mask Refine node

Using the Mask Refine node, I was able to correct the mask boundaries quite cleanly.
On the other hand, since the Mask Refine node adjusts the boundaries after applying a blur, it has the drawback that thin parts of the hair become faint and the "corners" surrounded by the mask become rounded.
Every node that automatically adjusts masks has its strengths and weaknesses, so it is best to use them selectively depending on the case.
There are also subjects that BiRefNet is not good at
BiRefNet mainly separates the foreground and background based on color and texture, but if there is a similar structure in the boundary area, the separation accuracy decreases.
I will try the previous workflow with a different illustration.
Input Image 2

BiRefNet → Mask Threshold → Mask Refine

In this illustration, part of the fireworks that are similar in color and brightness to the hair were incorrectly identified as the foreground.
Also, the area of the small patch of sea surrounded by hair in the bottom right was not recognized as the background and was included in the foreground.
Therefore, I will consider a method to improve the separation accuracy using a different model.
Depth-Anything-V3 estimates depth.
Depth-Anything-V3 is a model released by ByteDance in China that performs monocular depth estimation (estimating depth from a single illustration).
To perform depth estimation accurately, multiple lenses or more are typically required as input, but the Depth-Anything-V3 model can perform depth estimation with considerable accuracy even with a single lens by training on a large number of images.
The Depth-Anything-V3 model can also be used with ComfyUI standard nodes, just like the BiRefNet mentioned earlier.
Let's try using the Depth-Anything-V3 model!
Now, let's actually perform depth estimation using the Depth-Anything-V3 model.
Workflow

Model
geometry_estimation: depth_anything_3_mono_large.safetensors
Installation folder
ComfyUI\models\geometry_estimation (create a new folder)
Monocular depth estimation with Depth-Anything-V3

When you create a depth map using the Depth-Anything-V3 model, you can see that the character comes to the foreground, and the fireworks and the sea area surrounded by hair are correctly recognized as the background.
Determining the foreground from the depth map
Now, let's actually extract the foreground from the depth map.
Workflow

Model
background_removal: birefnet.safetensors
Custom Nodes
First, we remove the area detected by BiRefNet from the depth map created by Depth-Anything-V3, masking the unnecessary parts in black and cropping it.

Next, since the depth map exists as a gradient from black to white, we look for the threshold to separate the foreground and background.
Convert Image to Mask After converting the depth map to a mask, connect it to the Auto Mask Threshold node.

The Auto Mask Threshold node analyzes the mask's histogram (frequency distribution) and proposes 8 appropriate threshold candidates.
This time, the 5th output in the center looked good, so I set the threshold to 5 and executed it.

Finally, adjust the boundaries through Mask Refine.
In this way, by combining BiRefNet and Depth-Anything-V3, I was able to correctly separate the background from the area surrounded by fireworks and hair.
Remove unwanted objects with Lama Remover!
Finally, I will introduce how to use Lama Remover.
Lama Remover is a custom node that allows you to use LaMa, an image inpainting model I introduced previously, in ComfyUI.
About image inpainting with the LaMa model
Workflow

Models
checkpoints: sam3.1_multiplex_fp16.safetensors
lama: big-lama.pt
Installation folder for sam3.1_multiplex
ComfyUI\models\checkpoints
Installation folder for big-lama.pt
ComfyUI\models\lama (create a new folder)
Custom Nodes
comfyui-lama-remover (revived)

Detect the target to be removed with SAM 3.1
First, detect the target you want to remove using the SAM 3.1 model.
This time, I will try removing the fireworks and bokeh lighting from the following illustration.
Input Image 3

Prompt
fireworks:10, bokeh lights:30
When you want to detect multiple objects simultaneously with the SAM 3.1 model, you can write the number of items after the colon, and it will detect up to that many at once.

Remove unwanted objects with Lama Remover!
Next, connect the original illustration and the mask area to the Big Lama Remover node to remove the target.

In this way, by combining the two AI models, SAM 3.1 and LaMa, we were able to easily remove unwanted objects.
Since both SAM 3.1 and LaMa are lightweight and fast models, I think they can be very useful in the pre-processing of illustration editing.
Summary: Using AI in combination!
BiRefNet separates the background
Depth-Anything-V3 estimates depth
Combine SAM 3.1 and LaMa to remove unwanted objects
This time, I introduced how to use the SAM 3.1, BiRefNet, Depth-Anything-V3, and LaMa models in ComfyUI.
Today, many AI models are released with open weights, and even just within the technology of segmentation for detecting regions from images, it is impossible to simply determine the superiority of performance.
Comparison video of segmentation models by Bracer Jack
AI models each have their strengths and weaknesses, but by combining multiple models, you can use them to cover each other's shortcomings.
Recently, ComfyUI has officially supported many more models, making it easier to try out new ones, which has opened up infinite possibilities.

Why not take this opportunity to try out some new models yourself?
Thank you for reading until the end!
Update History
2026.8.10
Partially updated the workflow

