Polygon To Mask
Turn a panel polygon into an actual mask, ready for inpainting
- polygon
- bbox_window
- MASK
Polygon To Mask is the conversion you reach for when you stop thinking in panel shapes and start thinking in pixels. This pack's panels are shapely.Polygon objects - crisp vector geometry - but ComfyUI's inpainting, masking, and compositing nodes operate on raster MASK tensors. This node bridges the two: it rasterizes a polygon into a white-on-black mask tensor you can feed to anything that expects a MASK.
In a comic-page workflow this shows up all over the place. You build a page of panel polygons, and now you want to inpaint art inside a single panel while leaving the neighbors alone - that needs a mask of that one panel. Or you want to blank out the panel area so you can generate into it. Every one of those starts with this node (or its fancier sibling, Polygon To Resized Mask).
The mechanism is unglamorous and reliable: it computes the polygon's bounding box, creates an image of exactly that size, and draws the polygon filled in white. The output MASK is therefore the size of the polygon's bounds, not of any page. That's the main thing to wrap your head around - the mask doesn't know about the rest of the page unless you tell it.
Which brings up the one optional input that matters:
- polygon - the panel to rasterize.
- bbox_window (optional) - a BBOX that defines the area the mask should cover. Feed in the full page's bbox here and you get a mask that's page-sized with the panel filled in - which is what you want when the mask has to line up with a full-page image for inpainting. Leave it empty and the node just uses the polygon's own bounds.
Output is a single MASK, ready for ComfyUI's Set Latent Noise Mask / inpainting stack or for masking-based compositing.
When do you use this one vs Polygon To Resized Mask? This one keeps coordinates 1:1 with whatever bbox window you gave it - no resizing, no padding, honest pixel positions. That makes it the right choice when the mask must match a specific image's dimensions exactly. The resized variant exists because downstream generation often wants fixed, divisible resolutions - but it costs you extra bookkeeping. If your pipeline doesn't need the resize, this is the simpler node and the one I'd grab first.
One thing that trips people up: it's all CPU rasterization, so there's no quality knob - the mask is as sharp as the polygon. If the mask edge looks pixelated at extreme zoom, that's just what rasterizing a polygon at that resolution looks like; bump the bbox window's resolution if you need crisper edges.
Installing
Part of comfyui-panels by bmad4ever. Via ComfyUI Manager (search "comfyui-panels") and restart, or:
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_panels
The pack needs shapely, matplotlib, and opencv-python - no models, no GPU. Shapely is pinned exactly; a version conflict with another pack is the realistic import-time failure.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| polygon | POLYGON | — | |
| bbox_windowopt | BBOX | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | — |