Nodes/ComfyUI Layer Style/LayerMask: Image To Mask
ComfyUI Node Runs on cloud

LayerMask: Image To Mask

Pull a mask out of any color channel, with levels

By chflame163·Created 3 years ago·Updated 4 days ago· 3,113
LayerMask: Image To Mask
  • image
  • mask
  • mask
◄channel▾►
â—„black_point0â–º
â—„white_point255â–º
â—„gray_point1.00â–º
â—„invert_output_maskfalseâ–º

ComfyUI core already has an "Image To Mask" node, but it only lets you grab R, G, B, or alpha. This one is the upgrade you actually want: it can pull a mask from thirteen different channels - including LAB luminance, the individual Lab/YUV/HSV components, and alpha - and then it gives you levels control (black point, white point, gamma) to shape that mask before it leaves the node. That combination is what makes it useful, because the right mask is often hiding in a channel you'd never think to look at.

Classic use: you want to mask the bright parts of an image, or the sky, or a specific color region. Convert the smart channel to a mask, crush the levels so it's clean, and feed it into an inpaint or a composite. It's a quiet workhorse in this pack.

How it works

You pick a channel, the node extracts that single grayscale plane, then applies a levels remap so you can decide what becomes fully white (masked), what becomes black, and how the midtones roll between them. An optional incoming mask lets you constrain the result to a region you already have.

The inputs and outputs that matter

  • image (IMAGE) - the source.
  • channel - the channel to read, an enum of 13: L(LAB), A(Lab), B(Lab), R(RGB), G(RGB), B(RGB), alpha, Y(YUV), U(YUV), V(YUV), H(HSV), S(HSV), and one more. L(LAB) is your best all-purpose luminance mask; the HSV and Lab color channels are how you isolate by color/hue instead of brightness.
  • black_point / white_point (INT, 0–255) - the levels endpoints. Raise black and lower white to increase contrast and get a crisp, near-binary mask instead of a mushy gradient.
  • gray_point (FLOAT, 0.01–9.99, default 1) - gamma/midtone bias. Above 1 lifts the mids, below 1 darkens them.
  • invert_output_mask (BOOLEAN, default false) - flip the result if the wrong half came out white.
  • mask (optional MASK) - limit extraction to an existing region.

Output is a single mask (MASK).

How to install it

Through ComfyUI Manager: search ComfyUI Layer Style, install, restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/chflame163/ComfyUI_LayerStyle

Restart to install requirements. No model download for this one.

Common issues & troubleshooting

If the node's missing, it's the pack-level IMPORT FAILED situation. Check the console at startup for it on ComfyUI_LayerStyle. Two repeat causes across this pack: a stale install from before it was split into ComfyUI_LayerStyle and ComfyUI_LayerStyle_Advanced (delete and reinstall), or a broken dependency in your environment (a bad transformers/tensorflow combo, typically) crashing the import. Reinstall clean via Manager.

Using it: if your mask is a washed-out gray blob, that's levels - push black_point up and white_point down until it snaps to a clean shape. If you're masking a color and it's not isolating cleanly, try a different channel; a hue you can't separate in RGB often falls right out in HSV or Lab. And if the mask is inverted from what you wanted, that's a one-click invert_output_mask toggle, not a rewire.

Category😺dzNodes/LayerMask

Inputs (7)

NameTypeDefaultDescription
imageIMAGE—
channelCOMBO13 options: L(LAB), A(Lab), B(Lab), R(RGB), G(RGB), B(RGB), +7
black_pointINT00–255—
white_pointINT2550–255—
gray_pointFLOAT1.000.01–9.99—
invert_output_maskBOOLEANfalse—
maskoptMASK—

Outputs (1)

NameTypeDescription
maskMASK—