Nodes/comfyui-panels/Panel to Mask
ComfyUI Node

Panel to Mask

The node that turns panel shapes into something ComfyUI can actually use

By bmad4ever·Created 12 months ago·Updated 2 months ago· 41
Panel to Mask
  • panel
  • canvas
  • MASK

Here's the thing about the whole comfyui-panels pack: it does all its geometry in shapely Polygon objects, but ComfyUI itself doesn't know what a polygon is. It knows masks. So the moment you want a panel shape to do anything - constrain an inpaint, drive a regional conditioning, composite a crop back in - you need a bridge. This node is that bridge.

Panel to Mask takes one panel polygon and the canvas it lives on, and rasterizes it into a proper MASK tensor. Wire that mask into SetLatentNoiseMask before a KSampler and you've got panel-aware inpainting without touching any other tool. It's also the standard path when you want panel geometry to gate a controlnet preprocessor or to composite crops with masks. The pack's README points at Polygon To Resized Mask if you're feeding Paste Crops with Masks instead - different tool for a slightly different job, but this is the simpler one to start with.

How it works

Under the hood it's about twenty lines. It reads the canvas bounds, creates a grayscale image the size of the canvas, and draws the panel's exterior coordinates into it with PIL's ImageDraw, filled in and outlined with value 1. Then it wraps the result as a (1, H, W) float tensor. Nothing clever, nothing heavy - which is why it's fast and why you shouldn't overthink it.

Two assumptions are baked in, and they're worth knowing:

  • No holes, no multipolygons. The node says so itself in a comment. If your panel came out of Detect Panels In Image with weird non-convex recovery, a solid fill is still fine - but a ring-shaped panel won't rasterize the way you'd hope.
  • Panel coordinates are in canvas space. Both inputs must be in the same pixel coordinate system, which is exactly why the node asks for the canvas and not just the panel.

The inputs that matter

Only two, both required, both polygons:

  • panel - the panel shape you want masked.
  • canvas - the page it belongs to. This defines the mask's width and height, so a mask is only as good as the canvas matches the image you're working on.

Output is a single MASK, sized to the canvas, white where the panel is.

Installing it

This is part of comfyui-panels, not a standalone node. Easiest via ComfyUI Manager - search for "comfyui-panels" and install the pack. Or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_panels

Restart ComfyUI, let Manager install the Python deps (shapely, matplotlib, opencv-python), done. No model files, no API keys - it's all pure geometry.

Where people get burned

The classic mistake is mismatched coordinate space: you generate a 1024×1536 image, but your Canvas Panel is set to the default 2480×3508, and suddenly every mask is the wrong aspect ratio and your inpaint does nothing visible. Keep the canvas size in sync with the actual image you're processing. And remember that masked inpainting's whole remaining superpower is bit-identical pixels outside the mask - a panel mask lets you regenerate inside one panel without the rest of the page drifting, which is the one thing whole-frame edit models still can't promise you.

CategoryBmad/Panels

Inputs (2)

NameTypeDefaultDescription
panelPOLYGON
canvasPOLYGON

Outputs (1)

NameTypeDescription
MASKMASK