ComfyUI Node

Mask of Center

Mask the middle of the frame so a model focuses there

By zhangp365·Created 2 years ago·Updated 5 months ago· 134
Mask of Center
  • size_as
  • mask
  • width
  • height
width1024
height1024
top0.25
bottom0.25
left0.25
right0.25
redius0.05

The mirror image of this pack's corner-masking node: where MaskCoverFourCorners covers the edges, MaskofCenter covers the middle. Generate a soft-edged region in the center of your canvas and use it as an attention mask so whatever comes next spends its effort on the subject instead of the background and margins.

What it's for

The README frames it plainly: "this mask can be used as an attention mask, then model can focus on the center of the image." That's genuinely the whole use case - any workflow step that supports masked attention or masked conditioning can be told "care about this region more" by handing it a mask like this one, which is cheap and controllable compared to hand-painting the same shape every time. It's also usable as an inpaint mask in reverse: protect the center while editing everything around it, if that's the direction you need.

How it works

Rather than a fixed-size circle like the corner-masking node, this one defines its region by insets from each of the four edges - how much of the canvas, as a fraction, gets excluded on each side - then rounds the resulting shape's corners by a feather amount.

The inputs and outputs that matter

  • width / height (default 1024, step 8) - canvas size for the generated mask.
  • top / bottom / left / right (all default 0.25, range 0–1) - how much of the canvas, as a fraction from that edge, is excluded from the masked center region. At the defaults (0.25 each side), you end up with a masked region occupying the middle half of the frame in each dimension. Push any one of them up to shrink the mask from that side; push toward 0 to let the mask extend closer to that edge.
  • redius (yes, that's how it's spelled in the node - default 0.05, range 0–0.5) - how rounded/feathered the resulting shape's corners are, as a fraction of the canvas.
  • size_as (IMAGE, optional) - match the mask's canvas size to an actual image instead of typing width/height by hand.

Outputs: mask (MASK), plus width and height echoed back out - handy since you can drive the mask's size from size_as and still get the resolved numeric width/height to reuse elsewhere in the graph.

How to install it

Via ComfyUI Manager: search "ComfyUI-utils-nodes," install, restart. Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/zhangp365/ComfyUI-utils-nodes

Restart ComfyUI. Procedural mask generation only, no models to download, so install is quick.

Common issues & troubleshooting

The four inset fractions are independent, not a single "size" knob - it's easy to assume top/bottom/left/right are locked together and get a lopsided mask because you only adjusted one of them. If you want a mask centered and symmetric, set all four to the same value; if you actually want an off-center region (weighted toward the top of the frame, say), that's exactly what independently adjusting them is for, just be intentional about it.

Keep size_as or manually-matched width/height in sync with whatever image this mask is actually going to be applied to - a mismatched canvas size means the "center" region won't align with the actual center of your image once it's composited or used as an attention mask downstream. And don't expect this to be smart about content - it's a purely geometric center mask with no awareness of where your subject actually is in the frame. If your subject isn't centered, this mask won't find it; you'd want a detection-based mask instead for an off-center subject.

Categoryutils/mask

Inputs (8)

NameTypeDefaultDescription
widthINT10240–8096
heightINT10240–8096
topFLOAT0.250–1
bottomFLOAT0.250–1
leftFLOAT0.250–1
rightFLOAT0.250–1
rediusFLOAT0.050–0.5
size_asoptIMAGE

Outputs (3)

NameTypeDescription
maskMASK
widthINT
heightINT