ComfyUI Node

Resize Mask

The scale-and-crop node masks have been missing

By silveroxides·Created 2 months ago·Updated about 7 hours ago· 24
Resize Mask
  • mask
  • MASK
  • width
  • height
width512
height512
keep_proportionsfalse
upscale_methodbilinear
cropdisabled

Masks are forever living at the wrong resolution. Your subject mask came out at the source image's size, your latent is a 1024×1024 canvas, and your inpainting or compositing node expects the two to match or it quietly ignores the mismatch or does something worse. UC_ResizeMask is the scale-and-crop utility that fixes that, with two extras most one-liner resize nodes skip: aspect-ratio preservation and honest reporting of what it actually produced.

What it does

Inputs: a mask (MASK), target width and height (both default 512, up to 16384), a keep_proportions boolean, an upscale_method, and a crop mode. Outputs: the resized MASK, plus the real width and height as INTs.

The core behavior mirrors ComfyUI's image scaling: pick your interpolation from nearest-exact, bilinear, area, bicubic, or lanczos, and optionally center-crop while resizing instead of squeezing to the target box. The details are where it gets useful:

  • width/height of 0 means "keep the original dimension." Set width to 0 and height to 1024 and you get a mask scaled only vertically. This is the "match the other axis" move.
  • keep_proportions fits the mask inside the requested box without distorting it - it scales by the smaller ratio, so a 2:1 mask asked to fit 1024×1024 becomes 1024×512, letterboxed rather than stretched. Turn it on for subject masks you want to preserve.
  • The width/height outputs tell you the truth. With keep_proportions on, the actual result rarely equals your request. Wiring those outputs downstream (say, into a resolution picker or a canvas-size computation) beats guessing what the mask ended up as.

Which interpolation

For hard binary masks, nearest-exact keeps edges crisp and avoids the gray halo that bilinear feathering introduces. For soft alpha masks - the kind background-removal models emit - lanczos or bicubic preserve the smooth falloff. area is the downscale-safe choice when shrinking a mask a lot. The crop: center option is worth remembering: it gives you a "resize then center-crop to fill the box" behavior, which is the opposite philosophy of keep_proportions and is what you want when the mask must exactly fill the canvas no matter what.

Where it slots in

Anywhere a mask has to meet a latent or image at a specific resolution: pre-inpainting so your mask lines up with the latent you'll decode, in a compositor so the subject mask matches the background canvas, or in front of a ControlNet that takes a resized conditioning mask. Because it returns the actual dimensions, you can chain it into a Resize Image that follows the mask rather than the other way around.

Install

It's one node in the big ComfyUI-UtilsCollection pack:

cd ComfyUI/custom_nodes
git clone https://github.com/silveroxides/ComfyUI-UtilsCollection

Restart, or install via ComfyUI Manager (search "UtilsCollection"). No model downloads for this one; the pack's opencv-python requirement does the heavy lifting and auto-installs.

Gotchas

Nothing exotic. Remember 0-means-keep when you see a mask come back at an unexpected size, and if you resize a soft mask with nearest-exact you will bake in hard edges - pick the interpolation to match whether your mask is binary or feathered. Pack-level note: UtilsCollection also owns the logic/primitive replacements for ComfyUI-LogicMath, so a "replace node?" prompt on workflow load is this pack migrating an old ID, not a problem with your graph.

Categoryutils/mask

Inputs (6)

NameTypeDefaultDescription
maskMASK
widthINT5120–16384
heightINT5120–16384
keep_proportionsBOOLEANfalseFits the mask inside the requested width and height while preserving its aspect ratio.
upscale_methodCOMBObilinearInterpolation used to resize the mask.
cropCOMBOdisabledCenter crops while resizing when enabled; disabled resizes to the calculated dimensions.

Outputs (3)

NameTypeDescription
MASKMASK
widthINT
heightINT