Create Mask by xywh
Draw a synthetic mask instead of hand-painting one
- bboxes1
- bboxes2
- mask
- mask_inverted
Sometimes you don't want a mask painted by hand or produced by a detector - you want a plain geometric shape at a known location, generated on the fly. That's what this node does: pick a shape, size it, place it, and it builds you a MASK (plus the inverted version) from pure numbers. No image needed, no drawing tool.
How it decides what to draw
Two modes, and they're mutually exclusive in a way the node's own description spells out directly: "bboxes input will override the shape and width/height parameters." If you wire something into the optional bboxes1/bboxes2 inputs, the mask gets built from those boxes and your shape/location_x/location_y/shape_width/shape_height settings are ignored. Leave both bboxes inputs empty, and it falls back to drawing the shape you picked - circle, square, or triangle - at the position and size you specified.
frames controls how many mask frames get generated at once, from 1 up to 4096 - useful for building a mask sequence to feed a video-length pipeline rather than a single still mask. grow expands or shrinks the shape's edges after drawing (negative values shrink it), which is a quick way to pad or tighten a mask without a separate grow/erode node afterward.
Inputs that matter
shape(circle/square/triangle, defaultsquare) andframe_width/frame_height(canvas size, default 512×512) - set these to match whatever image you're eventually going to composite the mask against.location_x/location_y(default 256, 256) andshape_width/shape_height(default 128×128) - where the shape sits and how big it is, both optional but you'll almost always want to override the defaults for anything besides a centered test mask.bboxes1/bboxes2(optionalBBOX) - wire these in instead if you already have a box (from a detector,KY_BBoxPosition, orKY_JSONToBBox) and want the mask to match it exactly rather than drawing a fresh shape.
Two outputs: mask and mask_inverted - getting both at once saves a separate Invert Mask node when you need the region outside the shape instead of inside it.
Installing it
ComfyUI Manager: search ComfyUI-KYNode, install, restart. Or:
cd ComfyUI/custom_nodes
git clone https://github.com/yorkane/ComfyUI-KYNode
Restart ComfyUI. Pure geometry generation - no models, no external binaries.
Common issues
If you set location_x/location_y/shape_width carefully and the mask doesn't match at all, check whether you've also got something wired into bboxes1 or bboxes2 - per the node's own description, that silently takes over and ignores everything else, which is an easy thing to forget once a graph gets reused across a few workflows.
frame_width/frame_height (the canvas the mask is drawn onto) needs to match your actual image's dimensions, not just be "big enough" - a mask generated at 512×512 composited against a 1024×1024 image will land in the wrong place or scale wrong, since this node has no idea what image you're eventually pairing it with.
frames set high (into the hundreds or thousands) for a full-length video mask sequence is a legitimate use, but remember each frame is a full mask tensor - pushing frame_width/frame_height up at the same time multiplies memory use fast, so scale one or the other, not both, if you're hitting VRAM/RAM limits.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| shape | COMBO | square | 3 options: circle, square, triangle |
| frames | INT | 11–4096 | — |
| grow | INT | 0-512–512 | — |
| frame_width | INT | 51216–4096 | — |
| frame_height | INT | 51216–4096 | — |
| bboxes1opt | BBOX | — | |
| bboxes2opt | BBOX | — | |
| location_xopt | INT | 2560–4096 | — |
| location_yopt | INT | 2560–4096 | — |
| shape_widthopt | INT | 1281–4096 | — |
| shape_heightopt | INT | 1281–4096 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |
| mask_inverted | MASK | — |