Nodes/ComfyUI_Lam/图片转mask批量
ComfyUI Node

图片转mask批量

Turn a color channel into a mask — batch-friendly, one drop-down

By yanlang0123·Created 2 years ago·Updated 11 days ago· 77
图片转mask批量
  • image
  • MASK
channel

ImageToMasks (图片转mask批量) is a small, honest utility: take an image, pick a channel - red, green or blue - and get that channel back as a mask. The display name says "批量" (batch), which is the giveaway that it's built for the batch-oriented way ComfyUI_Lam likes to work: feed it a batched image tensor and it converts every frame in one go.

Why would you reach for this? Because ComfyUI's masking ecosystem works on grayscale masks, and there are plenty of moments you already have the mask as an image - a generated alpha, a colored matte, a channel you carved out in an editor - and just need it in MASK form to feed an inpaint node, a composite, or the pack's own ImageAddMask. This is the conversion step.

How it works

Trivial under the hood: it indexes the selected channel out of each image in the batch and returns it as a float mask tensor. No thresholding, no automatic segmentation, no guessing - you get exactly the channel you asked for, so the mask is only as good as the source channel. That's the feature and the limitation. If your image isn't already channel-separable, this node won't invent a mask for you.

The inputs and the output

  • image (IMAGE) - the input. Works on a batch, hence the name.
  • channel (enum: red / green / blue) - which channel to extract. There's no alpha option here; if you're after alpha, the pack's ImageAddMask does the alpha math instead.

Output: MASK, ready to wire into an inpaint region, a VAE encode mask, or any mask-consuming node.

Install

It's part of the pack, so the usual:

cd ComfyUI/custom_nodes
git clone https://github.com/yanlang0123/ComfyUI_Lam

and restart. No model downloads, no insightface, no execution.py patch - for a pure mask-conversion job you can ignore the README's heavy install steps entirely.

Common issues

  • Mask looks inverted from what you expected - you picked the wrong channel, or the source's white means the opposite of what your downstream node assumes. Flip the channel or invert the mask; there's no convention enforced here.
  • Mask is all gray mush - the source channel genuinely had no separation (e.g. extracting red from a grayscale image). Nothing to debug; the source is the problem.
  • Shape mismatch downstream - the mask comes out at the image's size but the consumer expected a different resolution. Resize the mask before it reaches the inpaint node.

For what it is - one image type to another with a single drop-down - it's hard to get wrong, and it does the batch case without a loop.

Categorymask

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
channelCOMBO3 options: red, green, blue

Outputs (1)

NameTypeDescription
MASKMASK