Nodes/ComfyUI-northTools/Load Image batch from Directory with indexes
ComfyUI Node

Load Image batch from Directory with indexes

Load a specific handful of images from a folder as one stackable batch

By northumber·Created about a year ago·Updated about a year ago· 4
Load Image batch from Directory with indexes
    • IMAGE
    • MASK
    • INT
    directory
    indices

    Folder loaders normally come in two flavors: load everything or load one file at a time. This node is the middle option - load exactly the images you name, and stack them into a single batch tensor. You give it a directory and a string of positions like 0,2,5,8, it goes and grabs those specific files, and hands you one IMAGE batch plus the masks and a count. It's the batch-processing counterpart to the pack's list-based loader, and the natural target for the index_string produced by BooleanIndexesToString.

    Indexes are zero-based, starting at [0] for the first image, exactly as the README states: 0,2,5,8,15.

    How it works

    On execution it lists the folder, keeps .jpg, .jpeg, .png and .webp files, sorts them alphabetically, and parses your indices string. Each index is validated against the file count - out-of-range entries are silently dropped, duplicates collapse to one, and the survivors are sorted. The selected images are opened with PIL (EXIF orientation applied), converted to RGB tensors, and glued into a single batch with torch.cat.

    Three outputs, none of them lists:

    • IMAGE - one stacked batch tensor of the selected images.
    • MASK - the alpha channel of each image as a mask, stacked the same way (a zero mask where there's no alpha).
    • INT - how many images actually got loaded, which is handy for feeding a batch-size-expected node or a counter.

    Inputs

    • directory (required) - absolute path to the folder.
    • indices - the comma-separated position string. Leave it empty and the node deliberately refuses to run, raising a "Waiting for valid indices string" exception - a quirk of the design, and one that can look like a stuck workflow if you forget to wire it.

    The gotcha that will bite you

    All images in one batch must share the same dimensions. The node stacks with torch.cat, and torch.cat will error the moment two selected images have different widths or heights. Load 0,1,2 from a folder where 0 is 1024×1024 and 1 is 512×512 and the whole thing dies with a tensor mismatch. If your folder mixes sizes, either use the list variant (LoadImagesFromDirByIndexList), which keeps every image separate, or pre-normalize your folder. This is the single most common failure mode people hit with this node, and it's not documented in the README.

    Worth knowing too: unlike the list-based loader, a missing directory here returns None instead of raising - so a bad path fails quietly rather than loudly.

    Install

    Manager → search "ComfyUI-northTools", or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/northumber/ComfyUI-northTools
    

    then restart. No models, no extra dependencies beyond pillow/numpy/torch, all already in ComfyUI.

    The pairing that makes it sing: run image checks across a folder, let BooleanIndexesToString convert which ones passed into an index string, and feed that straight into indices here. You get a clean batch of exactly the images that mattered - as long as they're all the same size.

    CategorynorthTools

    Inputs (2)

    NameTypeDefaultDescription
    directorySTRING
    indicesoptSTRING

    Outputs (3)

    NameTypeDescription
    IMAGEIMAGE
    MASKMASK
    INTINT