ComfyUI Node

Canvas BBox Mask

Bboxes turned into real mask tensors

By yichengup·Created 10 months ago·Updated 4 months ago· 59
Canvas BBox Mask
    • mask_1
    • mask_2
    • mask_3
    • mask_4
    • mask_5
    • mask_6
    • mask_7
    • mask_8
    • mask_9
    • mask_10
    • mask_batch
    • width
    • height
    canvas_width512
    canvas_height512
    mask_data

    Canvas BBox Mask is the sibling of Canvas BBox in the same pack - same drawing canvas, but instead of giving you coordinate strings, it gives you actual MASK tensors. You drag rectangles on the node face and each one comes out as a white rectangle on a black mask, at your canvas resolution. If your downstream pipeline eats masks rather than bbox strings, this is the node you want, and it saves you a string-to-mask conversion step entirely.

    The author's canvas-drawing code traces back to Smirnov75's ComfyUI-mxToolkit, and like its sibling it's a widget-first node: set the canvas size, draw, run.

    How it works

    You set canvas_width and canvas_height (64–4096). The rectangles serialize into mask_data as x,y,w,h;x,y,w,h;.... On run, the backend creates one all-black mask per slot and paints each region white (1.0), clamping coordinates to the canvas so off-canvas rectangles don't crash anything.

    Outputs:

    • mask_1 through mask_10 - one mask per drawn rectangle, in order.
    • mask_batch - all drawn regions stacked into a single (N, H, W) batch, which is what you'll feed batch-oriented mask consumers.
    • width, height - canvas size echoed.

    The honest caveats

    Unused slots come out as all-black masks, not empty. That's fine most of the time, but a stack of black masks in a batch will quietly do nothing - filter or slice before you feed a 10-slot output somewhere that assumes every entry matters. And this node gives you rectangular regions only; if you need soft or hand-painted masks, use the pack's Load Image Brush Mask instead. These two cover different jobs.

    Installing

    Same pack, same ritual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/yichengup/ComfyUI-YCNodes_Toolkit
    

    Restart, and it shows up under YCNodes Toolkit. Dependencies are numpy and Pillow - no models, no weight downloads. It's a small node, and it's best treated that way: a fast way to lay down several region masks for regional conditioning or targeted inpainting without opening any editor.

    CategoryYCNode/Mask

    Inputs (3)

    NameTypeDefaultDescription
    canvas_widthINT51264–4096
    canvas_heightINT51264–4096
    mask_dataSTRING

    Outputs (13)

    NameTypeDescription
    mask_1MASK
    mask_2MASK
    mask_3MASK
    mask_4MASK
    mask_5MASK
    mask_6MASK
    mask_7MASK
    mask_8MASK
    mask_9MASK
    mask_10MASK
    mask_batchMASK
    widthINT
    heightINT