ImageToMask_AS
Turn an image into a grayscale mask by averaging its RGB channels
- image
- MASK
ImageToMask_AS converts an IMAGE into a MASK by the simplest possible route: average the red, green, and blue channels together. Bright pixels become bright mask values (1), dark pixels become dark mask values (0), and everything in between becomes a shade of gray. One input, one output, no options, nothing to configure.
It's part of flyingshutter's As_ComfyUI_CustomNodes pack - a personal playground project with the author's own disclaimer that nothing is guaranteed to work - and like the rest of the pack it needs no dependencies beyond what ComfyUI ships.
How it works
The whole node is effectively one line: image.squeeze().mean(2). It drops the extra dimensions (squeezing down the batch/channel axes) and averages across the color channels, producing a single-channel MASK tensor with values in the 0–1 range. No thresholding, no edge detection, no magic - it's a grayscale conversion with the "luminance" being a plain mean instead of the weighted average you'd get from a proper RGB→Luma conversion.
The inputs that matter
image- theIMAGEto convert. That's the only input, and the output is aMASK.
Because it's just a mean across channels, the quality of your mask depends entirely on your source image. A black-and-white image converts cleanly. A colorful image averages its channels, so a red subject on a blue background turns into similar mid-gray values on both - you lose the separation you thought you had. For predictable masks, feed it grayscale input.
Where you'd use it
Masks are the currency of inpainting and compositing in ComfyUI, and images are the currency of almost everything else, so this node is the bridge between the two. Pattern: load a black-and-white PNG you drew in any editor, convert it to a MASK, and feed it into an inpaint workflow or into a masked-blend node like ImageMixMasked_As from this same pack. It also pairs with MaskToImage_AS (also in this pack) if you ever need to bounce a mask back into image space to preview or edit it.
Installing it
cd ComfyUI/custom_nodes
git clone https://github.com/flyingshutter/As_ComfyUI_CustomNodes
Restart ComfyUI and it appears under ASNodes - or install via ComfyUI Manager by searching "As_ComfyUI_CustomNodes". There is no requirements.txt; the pack deliberately avoids extra dependencies.
Common issues
- Batch size. The
squeeze()call assumes you're feeding a single image. Feed it a batch and the shape handling gets fragile - you can end up averaging the wrong axes or an outright error. Keep it to one image at a time. - Colored input giving muddy masks. Expected, given the averaging. Convert to grayscale first if you need separation, or use a dedicated segmentation/background-removal tool for real subject extraction - the KB's background-removal coverage is worth a read for that.
- It's not a threshold. The output is continuous grayscale, not a hard 0/1 binary mask. If you need binary, chain a thresholding step after it.
For a one-line conversion, that's honestly all there is to it. It won't do the thinking for you, but it's the fastest way to get an image into mask-land.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | — |