Nodes/ComfyUI_Antonioilev_Lightpack/πŸ’Ύ Save Batch Images with Alpha Mask
ComfyUI Node

πŸ’Ύ Save Batch Images with Alpha Mask

PNGs With a Real Alpha Mask, Courtesy of rembg

By AntonioilevΒ·Created 2 days agoΒ·Updated a day agoΒ· 0
πŸ’Ύ Save Batch Images with Alpha Mask
  • bc
  • nm
  • pos
  • preview
β—„pathL:/AI_3d/outputβ–Ί
β—„filenameviewβ–Ί
β—„low_vramtrueβ–Ί

What it's actually for

Texture-projection passes need cutouts. When you project six views of a character onto a mesh, the background around the subject shouldn't be projected at all - it should be masked out. Without alpha, every view paints its own backdrop into the texture and you get a halo of whatever the renderer had behind the model.

This is the alpha variant of the pack's batch saver: same bc/nm/pos writing, but each image gets a background-removal pass first and is written as RGBA PNG. In the workflow it sits between your render passes and your texture projection, and its whole job is producing clean cutouts at volume.

How it works

The node writes {filename}_{bc|nm|pos}_{n}.png as RGBA, exactly like the plain saver's layout - so a graph can swap one for the other without renaming anything downstream. The difference is the mask generation.

For each image it serialises the PIL image to PNG bytes and pipes them into the rembg CLI as a subprocess (rembg i, stdin to stdout), then takes the alpha channel of the returned RGBA and applies it to the original. That's an unusual design choice and worth understanding: rather than importing rembg as a Python module - where version conflicts with torch, onnxruntime and the rest of a ComfyUI environment are a known nuisance - it shells out to the command-line tool, which runs in its own process with its own dependencies. Clever, and also the reason this node has a hard external requirement.

Background removal is a genuinely commoditised operation in this ecosystem, and rembg is the front end nearly everyone reaches for. The quality caveat is the same one that shows up in every thread about it: on hair, fur, semi-transparent material and thin structure, a segmentation-style cutout is visibly wrong, and a soft matte is what you actually want. For a hard-surface prop or a solid character against a plain backdrop, it's fine. For flyaway hair, expect to fix edges by hand.

The low_vram flag is passed into the removal call; note that in the shipped code it's accepted and threaded through but the CLI invocation itself doesn't change, so treat it as reserved rather than as a working lever.

The inputs that matter

  • bc / nm / pos - all three are required here, unlike the plain saver where they're optional. An unconnected socket means a validation error, so wire all three (or use the non-alpha node when you don't need them).
  • path (default L:/AI_3d/output) and filename (default view) - same convention as the sibling node.
  • low_vram (default on) - accepted, passed through, not currently plumbed into the subprocess call.

One output: preview (IMAGE), the RGBA batch for a viewer.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/Antonioilev/ComfyUI_Antonioilev_Lightpack.git
# restart ComfyUI

Then the part people miss - rembg must be a command on PATH, in the same environment ComfyUI runs in:

pip install "rembg[cli]"
rembg --help    # verify it resolves; use an absolute path if it doesn't

Manager search for the pack is "Antonioilev Light Pack". No requirements.txt ships with the repo, so nothing installs rembg for you, and the pack's __init__.py swallows import errors - meaning the node appears normally, and only fails at execution.

Where people get burned

  • rembg failed: ... at run time, node looks fine. The CLI isn't installed or isn't on the ComfyUI process's PATH. This is the single most likely failure with this node.
  • On Windows, rembg not being a .exe on PATH is common - install into the same venv/conda env as ComfyUI and check from a shell started the same way the server is.
  • Removal runs per image, so a six-view batch of three channels is eighteen subprocess calls. That's slow by nature; on a big batch, budget for it rather than assuming the node hung.
  • The model has to download on first run. The first invocation can sit there for a while fetching weights; it hasn't crashed.
  • The nm and pos passes get masked too. Usually what you want (consistent alpha across channels), occasionally not, if you needed the full normal render for something else.
CategoryAntonioilev/IO

Inputs (6)

NameTypeDefaultDescription
bcIMAGEβ€”
nmIMAGEβ€”
posIMAGEβ€”
pathSTRINGL:/AI_3d/outputβ€”
filenameSTRINGviewβ€”
low_vramBOOLEANtrueβ€”

Outputs (1)

NameTypeDescription
previewIMAGEβ€”