Nodes/ComfyUI-UtilsCollection/Image and Mask Resize
ComfyUI Node

Image and Mask Resize

Resize the pixels and the mask, together

By silveroxides·Created 2 months ago·Updated about 7 hours ago· 24
Image and Mask Resize
  • image
  • mask
  • target
  • IMAGE
  • MASK
resize_methodlanczos
cropdisabled
mask_blur_radius0
width512
height512

Every masking workflow has this moment: you inpaint or composite at one resolution, and then you need the image and its mask to come along at a new size - and they must stay aligned. Resize them separately and a one-pixel drift between image and mask turns into a misaligned inpaint. UC_ImageAndMaskResize is the node that does both at once, which is exactly the kind of boring, correct utility that saves you a debugging session.

It's the pack's take on the classic "resize image and mask together" node, with a couple of nice details: it can resize to a reference image's dimensions instead of explicit numbers, it has a center-crop option, and it'll blur the resized mask for you.

How it works

You feed it image and mask. Target dimensions come from one of two places: an explicit width/height pair (optional, defaulting to 512 each), or a target reference image whose width and height are used whenever the explicit dimensions aren't connected. The image is resized with resize_method (default lanczos - pick nearest-exact if you're resizing pixel-art or a hard matte and want crisp edges), and the mask is resized the same way so the two stay pixel-locked.

Two knobs matter for masks specifically:

  • crop - disabled stretches directly to the target dimensions; center crops while resizing, keeping the center content. If you're changing aspect ratio, center is usually what you want for a subject.
  • mask_blur_radius - a Gaussian blur applied to the resized mask (default 0 = off). A few pixels of blur is the classic fix for hard mask edges that cause visible seams in composites.

Inputs and outputs

Required: image, mask. Optional: target, width, height. Outputs are IMAGE and MASK, matching the input pair, both at the same new size.

Installing it

ComfyUI Manager → search "ComfyUI-UtilsCollection", or:

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

Restart. Pack deps are opencv-python and typing-extensions - no models, no API keys. It uses the newer ComfyExtension API, so keep ComfyUI current.

The trap: if you connect explicit width/height and a target image, the explicit values win (they "override the target image width/height"). It's easy to leave a stale 512×512 wired in from an earlier experiment and wonder why your 1024 target is being ignored. Disconnect the explicit inputs and let target rule, or vice versa - pick one source of truth.

Categoryutils/image

Inputs (8)

NameTypeDefaultDescription
imageIMAGE
maskMASK
targetIMAGEReference image whose width and height are used when explicit dimensions are disconnected.
resize_methodCOMBOlanczosInterpolation used to resize the image to the target dimensions.
cropCOMBOdisabledCenter crops while resizing when enabled; disabled stretches directly to the target dimensions.
mask_blur_radiusINT00–256Gaussian blur radius applied to the resized mask; zero disables blur.
widthoptINT5121–16384Optional output width overriding the target image width.
heightoptINT5121–16384Optional output height overriding the target image height.

Outputs (2)

NameTypeDescription
IMAGEIMAGE
MASKMASK