image2mask
Batch background-removal masks for every frame of your video
- output_dir
image2mask is the mask factory for the EBSynth pipeline: point it at a folder of frames and it runs automatic background removal on every one, writing a matching mask for each. In the comfyui-imgmake workflow this is the step that decides what EBSynth is allowed to restyle - and if you've ever done style transfer on video, you know the mask quality is the result quality. Garbage masks mean EBSynth propagates garbage everywhere.
The tool underneath is transparent_background, the library built around InSPyReNet - an image-pyramid segmentation model that's been a community favorite for years (and still gets "absolute magic" reviews in background-removal threads). It's not the newest toy in the box; the pack just ships it as the default because it's reliable on complex edges like hair.
How it works
For each PNG in your input folder, the node runs the InSPyReNet remover, gets back a soft matte, then hard-thresholds it: anything below st1_mask_threshold gets zeroed out. The result is written as a grayscale mask PNG with the same filename as its source frame. It's a pure batch job - nothing goes to the GPU sampler, no diffusion involved.
There's a subtlety in the paths. The node takes an input_dir and output_dir, but then appends subfolders to both: it reads from <input_dir>/video_frame/ and writes to <output_dir>/video_mask/. So you pass it your project directory, not the frames folder directly. Feed it project_dir and it does the right thing for the EBSynth layout.
The inputs that matter
input_dir- your project dir; the node appendsvideo_frame.output_dir- your project dir; the node appendsvideo_mask.st1_mask_threshold- 0 to 0.5. The cutoff for what counts as "foreground". Too low and background noise creeps in; too high and you'll eat thin details like hair. 0 (the default) keeps the raw soft mask.tb_use_fast_mode/tb_use_jit- speed switches for the remover. Keep them on unless you hit memory or precision problems; turning them off is slower but sometimes steadier.device-cuda:0orcpu. On CPU this will be painfully slow for a whole video's worth of frames.
It returns one STRING, output_dir - the path it actually wrote masks to - which you can thread into the next node that needs the mask location.
Installing it
Part of the comfyui-imgmake pack - Manager (search comfyui-imgmake) or:
cd ComfyUI/custom_nodes
git clone https://github.com/dafeng012/comfyui-imgmake
Restart, and install the heavy dependency the README calls out separately:
pip install transparent-background
(It's in requirements.txt too, but the README's separate step is a hint that people miss it.) First run downloads model weights into ~/.transparent-background; if that fails, the README tells you to use a proxy or drop the model files in manually - there's a Baidu Pan pack linked for exactly this.
Troubleshooting
- No masks written - the node only globs
*.pngundervideo_frame, so runvideo2image(frame extraction) first. JPEG frame dumps won't match the glob. - Hair and edges look chewed - lower
st1_mask_thresholdtoward 0 so the matte's soft edges survive thresholding, and consider turningtb_use_fast_modeoff for a higher-quality pass. - Crash on import -
transparent_backgroundneeds torch; if your ComfyUI env is torch-adjacent but missing pieces, the separate pip install is usually the fix.
One honest caveat: this is a blunt instrument compared to a hand-drawn mask. For a subject that's easy to segment, great. For complex scenes, expect to clean up the important keyframes yourself - and honestly, that's where you should spend the effort, since EBSynth only needs great masks on the frames you actually paint.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| input_dir | STRING | — | |
| output_dir | STRING | — | |
| tb_use_fast_mode | BOOLEAN | true | — |
| tb_use_jit | BOOLEAN | true | — |
| st1_mask_threshold | FLOAT | 0.0 | — |
| device | COMBO | 2 options: cuda:0, cpu |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| output_dir | STRING | — |