Nodes/zhangp365/ComfyUI-utils-nodes/Load Image as Mask without Listing Input Dir
ComfyUI Node

Load Image as Mask without Listing Input Dir

The mask loader for when your input folder has thousands of files

By zhangp365·Created 2 years ago·Updated 5 months ago· 134
Load Image as Mask without Listing Input Dir
    • mask
    • enabled
    image
    channel
    enabledtrue
    mask_repeat_number1

    Stock ComfyUI's Load Image (as Mask) node has a quiet performance problem: every time it needs to build its file dropdown, it runs os.listdir on your entire input/ folder. That's instant with a few dozen files. It's noticeably not instant once you're running a batch pipeline that's dumped thousands of frames or masks into that directory - which is exactly the situation this node exists to fix.

    What it's for

    If you're doing anything programmatic - a script pushing hundreds of pre-rendered masks into ComfyUI's input folder, a video pipeline processing frame-by-frame, an automation loop calling the API repeatedly - the built-in loader's directory scan becomes a real, repeated cost on every single load. LoadImageMaskWithoutListDir avoids os.listdir entirely, so it stays fast regardless of how many files are sitting in the folder. For a one-off manual workflow with a handful of images, you won't notice a difference; this node earns its keep specifically at scale.

    How it works

    It's a drop-in replacement for the official Load Image Mask node with the slow directory enumeration removed - same job, same MASK output, just a different (and cheaper) way of resolving the file. On top of that it adds two conveniences the stock node doesn't have: a toggle to skip loading entirely, and a way to repeat the loaded mask into a batch.

    The inputs and outputs that matter

    • image - the file picker, same as the stock node.
    • channel (red / green / blue / alpha) - which channel of the source image becomes your mask. Alpha is the usual pick if your source has real transparency baked in; red/green/blue let you pull a mask out of a plain RGB image where one channel happens to encode what you want.
    • enabled (default true) - flip this off and the node skips loading, which pairs with the node's own enabled output: wire that into a downstream switch (like this same pack's ReferenceLatentSwitch or any bypass-style node) to conditionally skip a whole branch of your graph based on one toggle.
    • mask_repeat_number (default 1) - repeats the loaded mask this many times to build a batch, useful when you need the same mask applied across a batch of images without a separate repeat node.

    Outputs: mask (MASK) and enabled (BOOLEAN, the passthrough of your toggle).

    How to install it

    Via ComfyUI Manager: search "ComfyUI-utils-nodes," install, restart. Or by hand:

    cd ComfyUI/custom_nodes
    git clone https://github.com/zhangp365/ComfyUI-utils-nodes
    

    Restart ComfyUI. No model downloads - this is a filesystem-access change, not a new capability, so there's nothing extra to fetch.

    Common issues & troubleshooting

    The custom-node ecosystem in general has a reputation for dependency headaches (conflicting requirements.txt across packs is a recurring community complaint), but this specific node doesn't add any Python dependencies of its own - it's a lighter-weight rewrite of functionality ComfyUI already ships, so it shouldn't introduce new conflicts.

    The main thing to actually watch for is behavioral, not an error: because it deliberately avoids scanning the directory, don't expect the file dropdown to necessarily refresh and show a brand-new file the instant it lands on disk the same way the stock node's listdir-based picker would. If a file you just added doesn't show up immediately, that's the performance trade-off working as intended, not a bug - give the UI a refresh or restart if you're actively adding files mid-session rather than pre-populating the folder before you start.

    Categoryutils/mask

    Inputs (4)

    NameTypeDefaultDescription
    imageCOMBO0 options:
    channelCOMBO4 options: red, green, blue, alpha
    enabledoptBOOLEANtrue
    mask_repeat_numberoptINT1

    Outputs (2)

    NameTypeDescription
    maskMASK
    enabledBOOLEAN