ComfyUI Node

Pad Mask (Soze)

Grow a mask's canvas to match a padded image

By SozeInc·Created 2 years ago·Updated 5 days ago· 10
Pad Mask (Soze)
  • mask
  • mask
top_padding0
bottom_padding0
left_padding0
right_padding0

If you've extended an image's canvas - say, widening a portrait into a landscape before an outpaint - you need the mask to grow the same way, or the sampler won't know the new strip of canvas is even there. That's this node's whole job: it adds pixels of padding to a mask's top, bottom, left, and right edges independently, matching whatever padding you applied to the image itself.

How it works

Each of the four padding values controls one edge of the mask's canvas - this is padding the canvas the mask lives on, not dilating or shrinking the masked region within it. Set an edge to 0 and that side is untouched; set values on the sides you actually extended and the mask's canvas grows to match.

The inputs and output that matter

  • mask - the mask you're extending.
  • top_padding, bottom_padding, left_padding, right_padding - pixel counts for each edge, independently controllable, each defaulting to 0.

Output is a single mask, resized to the new padded dimensions.

One thing the schema doesn't spell out is what value fills the newly added strip - whether it comes in as masked (ready to generate) or unmasked (protected). Drop a Mask Preview node on the output the first time you use this so you know which way it reads before you build a whole outpaint workflow assuming one or the other.

Where it fits in an outpaint workflow

The typical shape: you pad your source image outward on one or more sides with an image-pad node (stock ComfyUI or WAS Node Suite both have one), which gives you a bigger canvas with the original photo sitting inside it and new blank space around it. The sampler needs to know that new space is exactly what it should be generating - that's what the mask communicates. If your mask is still the original, unpadded size, it simply won't line up with the new canvas, and depending on how your KSampler/inpaint node handles a size mismatch, you'll get an error or a mask that's silently misapplied to the wrong region. Pad Mask exists purely to keep the mask in lockstep with whatever you did to the image, using the exact same pixel counts on each edge.

Installing it

ComfyUI Manager: search ComfyUI_Soze. Manual: cd ComfyUI/custom_nodes && git clone https://github.com/SozeInc/ComfyUI_Soze.git, pip install -r ComfyUI_Soze/requirements.txt, restart. Pure tensor padding - no models, no extra dependencies.

Common issues

The main mistake is padding the mask without padding the image by the same amounts on the same sides - the two need to line up pixel-for-pixel, or your sampler ends up trying to reconcile a mask and an image of mismatched dimensions. Pad the image first with whatever canvas-extend node you're using, note the exact numbers, then feed the same four values in here.

Categorysoze

Inputs (5)

NameTypeDefaultDescription
maskMASK
top_paddingINT0
bottom_paddingINT0
left_paddingINT0
right_paddingINT0

Outputs (1)

NameTypeDescription
maskMASK