Nodes/Pseudocomfy/Reshape Mask
ComfyUI Node

Reshape Mask

Erode and dilate your regions like a pro

By Pseudotools·Created 2 years ago·Updated 19 days ago· 4
Reshape Mask
  • msks_list
  • msks
operationdilate (grow white areas)
kernel_size3
iterations1
invertfalse

Sometimes your mask isn't wrong, it's just the wrong size. The window region is a hair too big and is swallowing the wall material. The floor mask doesn't quite reach the baseboard. Before you redraw anything, you want to grow or shrink the region by a few pixels - which is exactly what Reshape Mask does, with the classic morphological operations: erode and dilate.

The mental model is a paint roller moving across the mask. Dilate pushes the white region outward in every direction, growing it. Erode eats into the white region from the edges, shrinking it. The mechanics are implemented with max-pooling, which is the standard cheap-and-clean way to do this on GPU tensors, and the operation repeats iterations times so each pass grows or shrinks a bit more.

The controls

  • operation - dilate (grow white areas) (default) or erode (shrink white areas). The names are unambiguous; pick the direction you need.
  • kernel_size (default 3, range 1–31, step 2) - the size of the square structuring element. Bigger kernel = more pixels affected per pass. Odd-only stepping keeps the element centered.
  • iterations (default 1, range 1–10) - how many times the operation is applied. Two iterations at kernel 3 erodes/dilates roughly twice as far as one. For big adjustments, prefer iterations over a giant kernel - it's easier to reason about.
  • invert (default off) - flips the mask after the operation. Handy when you want to erode the background instead of the region, or when your source polarity is reversed.

How to actually use it

  • Shrink a region to keep one material from bleeding into its neighbor: a light erode (kernel 3, 1–2 iterations) on the region mask before conditioning is a classic fix for edge bleed in regional prompting.
  • Grow a region to make a material's influence more generous - the floor reaches further, the sky covers more frame.
  • Clean up after thresholding or aggregation: erode removes stray specks and thin tendrils, dilate fills small holes. Run a small erode-then-dilate pair and you get a de-noised mask with its overall shape intact.

The traps

  • Erode can delete regions entirely. If the white area is thinner than the kernel, erosion eats it to nothing. Your mask disappears and your render shows the region completely un-conditioned - confusing until you remember you eroded it.
  • No anti-aliasing. These are hard morphological operations, so the result has pixel-staircase edges. Follow up with PseudoMaskBlur (and maybe PseudoMaskClamp) to feather what the reshape sharpened.
  • Iterations multiply. Ten iterations at kernel 3 is a lot of shrinking/growing. Start at 1–2, look at the result, iterate.

List in, list out, same shapes as the rest of the pack's mask nodes. Ships with Pseudocomfy - clone Pseudotools/Pseudocomfy into custom_nodes and restart, or find it in Manager.

CategoryPseudocomfy/Utils

Inputs (5)

NameTypeDefaultDescription
msks_listMASK
operationCOMBOdilate (grow white areas)2 options: erode (shrink white areas), dilate (grow white areas)
kernel_sizeINT31–31
iterationsINT11–10
invertBOOLEANfalse

Outputs (1)

NameTypeDescription
msksMASK