Nodes/comfyui_imgutils/BBox to Mask
ComfyUI Node

BBox to Mask

Fill a bounding box with a mask — the reverse direction nobody ships

By LK-168·Created about a year ago·Updated about a year ago· 1
BBox to Mask
    • MASK
    merge_optionsfalse

    When you need a rectangle to become a mask

    Mask to BBox exists because rectangles are convenient downstream. BBox to Mask is the less common reverse: you've got a bounding box and you want an actual mask - a filled rectangle in mask space. Why would you ever want that? Because a lot of ComfyUI machinery (regional conditioning, masked inpaint, cropping) eats masks, and sometimes the thing you have is "the detector said there's a person between pixels 40 and 380." This node turns that sentence into pixels.

    How it works

    For each box it builds a torch tensor of zeros the size of the reference image and fills the box coordinates with 1.0. Coordinates are clamped to the image bounds, so an overhanging box just gets clipped. Then:

    • merge_options = true - all boxes land in one mask. The mask takes its dimensions from the first box's image, and overlapping boxes just union together.
    • merge_options = false - each box gets its own separate mask, returned as a batch. That's the "one mask per detected object" mode, handy if you're looping or want to address regions individually.

    One honest note: the schema captured by comfy.icu for this node lists only merge_options as an input, but the pack's source shows the node genuinely takes a BBOX connection too - that's the box socket you see in the UI. Feed it the detection_bbox output of Imgutils Generic Detector, or the output of Mask to BBox. (That schema gap is a known quirk of how this node was crawled, not something you've done wrong.)

    Where it fits

    The pairing people actually use: detector → BBox Filter → BBox to Mask → mask-based inpainting. You get the detector's understanding of where things are, but expressed as a mask you can blur, morph, and hand to an inpaint node - without ever drawing anything by hand. Keep merge_options on unless you specifically want per-object masks.

    Install

    Part of LK-168/comfyui_imgutils. ComfyUI Manager → search "comfyui_imgutils", or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/LK-168/comfyui_imgutils
    

    Restart ComfyUI. Pure tensor math, no model downloads for this node.

    Gotchas

    • Empty or malformed box input produces a warning and an empty mask tensor - downstream, that looks like "nothing happened." Feed it a valid BBOX from a detector or Mask to BBox and sanity-check with Mask Info (0% coverage = empty).
    • merge_options off returns a batch of masks. If you then wire that straight into a node expecting a single mask, behavior depends on the consumer. When in doubt, merge.

    It's a three-line idea, but a genuinely missing piece in most ComfyUI installs - you'd otherwise be hand-drawing masks or fighting the coordinate system. Cheap, boring, useful.

    Categoryimgutils/bbox

    Inputs (1)

    NameTypeDefaultDescription
    merge_optionsBOOLEANfalseIf True, merge all bounding boxes into one mask. If False, create separate masks for each bbox.

    Outputs (1)

    NameTypeDescription
    MASKMASK