Nodes/Basic data handling/load MASK from alpha channel
ComfyUI Node

load MASK from alpha channel

Turn an RGBA file's alpha channel into a mask

By StableLlama·Created about a year ago·Updated 4 days ago· 48
load MASK from alpha channel
    • mask
    • exists
    path

    Basic data handling: PathLoadMaskFromAlpha ("load MASK from alpha channel") extracts a mask from the alpha channel of an image - no image output, just the mask, plus an exists flag. If your source of truth is a transparent PNG whose alpha is the selection, this is the leanest way to get that selection into the graph.

    Here's the workflow that makes it click. You have cutouts with transparency - logos, stickers, product shots, subjects knocked out in Photoshop or any editor. Those files encode the region you care about in their alpha. Feed the file path here and the alpha becomes a mask you can pipe into inpainting, compositing, or any mask-using node - without loading the full image tensor you don't need. Where the pack's RGBA loader gives you image and mask, this one gives you just the mask; when that's all you want, it's one less wire cluttering the graph.

    How it works

    It opens the image with Pillow and pulls the alpha channel, converting it to a float tensor in the 0–1 range and inverting it: 1.0 - alpha. So fully transparent pixels become 1 (white), fully opaque become 0 (black). That matches ComfyUI's mask convention - white marks the region that gets erased, replaced, or inpainting attention - rather than the raw PNG convention where alpha is the opposite.

    A couple of implementation notes:

    • No alpha → blank mask. A plain RGB file has no alpha channel, so you get an all-zero (black) mask, not an error. The loader also handles palette-mode PNGs that carry a transparency entry by converting to RGBA first.
    • Missing file → empty 1×1 mask + exists=False. Graceful, same as the pack's other loaders. Gate on the flag if a silent blank would be bad.

    Inputs and outputs

    • path (STRING, default "") - the image file to read alpha from.
    • mask (MASK) - the alpha as a mask, white = transparent, in ComfyUI orientation.
    • exists (BOOLEAN) - True if the file loaded.

    Installing it

    Part of Basic data handling, no dependencies beyond what ComfyUI ships. ComfyUI Manager → search "Basic data handling" → install → restart. Manual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
    

    Restart after. No models.

    Gotchas

    The orientation question is the recurring one: the mask is inverted from the raw alpha by design, because ComfyUI masks treat white as "operate here." If your inpaint/composite comes out backwards, that's the first thing to check, and flipping it is one mask-invert node away. And don't expect this to recover a mask from a JPEG - JPEGs have no alpha channel, so you'll get a blank black mask every time. For anything with real transparency, though, it's a clean one-node extraction that slots straight into mask pipelines.

    CategoryBasic/Path

    Inputs (1)

    NameTypeDefaultDescription
    pathSTRING

    Outputs (2)

    NameTypeDescription
    maskMASK
    existsBOOLEAN