Just Mask Those Pads
A mask that marks the gray bars, not the picture
- reference
- image
- pad_mask
Here's the scenario that made this node exist. You padded an image to fit a target frame - say a 1024×1024 square letterboxed into a 720×1280 portrait - and now you want to inpaint the gray bars away so the model fills in a proper background. To do that you need a mask that says "this is the fake part, regenerate it." Just Mask Those Pads gives you exactly that: a binary mask where 1.0 = padded region, 0.0 = real pixel.
It's the inverse of the mask that its sibling node Just Pad or Crop It produces (that one marks real pixels as 1.0). Same inputs, same alignment logic, but the mask convention flipped for inpainting samplers - which is the convention the diffusion world mostly wants: masked areas are the areas that get regenerated.
Inputs and the one that bites
- reference - defines the target size.
- image - the original, pre-pad image. Fun fact: this node only uses its dimensions. It doesn't read the pixels at all.
- alignment -
centerortop-left, and this is the trap: it must match the alignment you used when you padded the image. The tooltip on the node says it plainly. Get it wrong and your mask will be a rectangle sitting in the wrong place, pointing the inpainter at real pixels and leaving actual gray bars unmasked. It won't error; it'll just be subtly wrong.
How to use it in a real pipeline
The workflow is: reference image → Just Pad or Crop It to produce the padded frame → this node with the same reference and original to produce the pad mask → feed both into an inpainting sampler with a masked-denoise setup. The mask tells the sampler to regenerate only the bars, and because the real pixels never get touched, the output is a full-frame image where your original content is bit-identical to what you started with.
That's the one thing masked inpainting still owns outright in 2026, per the KB's inpainting essay: every instruction-edit model re-emits the whole frame and drifts the pixels. With a proper mask, the unmasked region doesn't move. This node is the 20-second version of that setup for the pad-and-fill case.
Install
Ships in TrentNodes:
cd ComfyUI/custom_nodes
git clone https://github.com/TrentHunter82/TrentNodes.git
cd TrentNodes
pip install -r requirements.txt
Restart and find it under Trent/Image. Like its sibling, it's pure tensor math - no model downloads.
Gotchas
One subtle behavior worth knowing: if your image is already at or larger than the reference on both axes, there's nothing to pad, so the node returns an all-zero mask (no pads to fix). That's correct - just don't stare at a black mask wondering if it broke. And if you only ever pad one axis, only that axis shows up as 1.0. The mask is always reference-sized, matching exactly where the pads went.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| reference | IMAGE | Reference image whose height and width define the target size | |
| image | IMAGE | Original image before padding/cropping (used only for its dimensions) | |
| alignmentopt | COMBO | center | Must match the alignment used in Just Pad or Crop It |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| pad_mask | MASK | Binary mask: 1.0 = padded region, 0.0 = real pixel |