ComfyUI Node

Base64 To Mask

Decode a base64 image into a mask from one color channel

By lldacing·Created 3 years ago·Updated 8 months ago· 96
Base64 To Mask
    • MASK
    base64Images[""]
    channelred

    Base64ToMask is the mask-focused sibling of Base64ToImage: instead of decoding a base64 string into a full IMAGE-plus-MASK pair, it decodes it and hands you back just a MASK - pulled from whichever color channel you tell it to read. That last part is the reason this node exists separately at all rather than you just decoding an image and extracting the mask yourself downstream: it lets you pick the channel in one step.

    It's another piece of comfyui-easyapi-nodes, lldacing's pack for API-driven ComfyUI graphs, and it earns its keep in the same place Base64ToImage does - anywhere your caller is sending image data as a string rather than a file, because they're calling ComfyUI's API directly instead of uploading through the browser. The specific case where you'd reach for this over the full image-decoding node is when the caller is sending mask data specifically, encoded from some other tool's channel convention, and you just need the mask out without also carrying the rest of the image through your graph.

    How it works

    Same JSON-array-of-base64-strings input shape as Base64ToImage, decoded the same way - but where that node splits into an IMAGE and a MASK derived from alpha, this node lets you choose exactly which channel of the decoded image supplies the mask values: red, green, blue, or alpha. That flexibility matters because not every source encodes mask data the same way; some tools bake a mask into the alpha channel, others use grayscale values in a color channel instead.

    The inputs and outputs that matter

    • base64Images (STRING, multiline, default ["" ], required) - the base64-encoded image data, as a JSON array of strings, same format as Base64ToImage.
    • channel (enum, default "red", choices red / green / blue / alpha) - which channel of the decoded image becomes the mask. If your source image's meaningful mask data lives in a specific channel, this is what points the node at it.
    • Output: MASK - the resulting mask, built from the chosen channel.

    How to install it

    Via ComfyUI Manager, searching comfyui-easyapi-nodes. Manual install:

    cd ComfyUI/custom_nodes
    git clone https://github.com/lldacing/comfyui-easyapi-nodes.git
    cd comfyui-easyapi-nodes
    pip install -r requirements.txt
    

    Restart ComfyUI. No model downloads - this is decoding plus channel extraction, CPU work throughout.

    Common issues & troubleshooting

    Mask comes out blank or solid. Wrong channel is the usual culprit - the default is red, but if your source data actually carries its mask in alpha (the more common convention for transparency-based masks), switch channel accordingly. Try each of the four options if you're not sure how the source encoded it.

    Input errors on the base64 field. Same requirement as Base64ToImage: the field expects a JSON array of strings, not a bare base64 string. Wrap a single value as ["<base64 data>"].

    Getting a MASK when you actually need the full IMAGE too. This node only returns a MASK - if you need both the image and a mask from the same base64 source, use Base64ToImage instead, which returns both, and derives its mask from alpha rather than a channel you choose.

    CategoryEasyApi/Image

    Inputs (2)

    NameTypeDefaultDescription
    base64ImagesSTRING[""]
    channelCOMBOred4 options: red, green, blue, alpha

    Outputs (1)

    NameTypeDescription
    MASKMASK