遮罩缩放丨尺寸
Scale a mask to a target size without touching the image it came from
- mask
- mask
- width
- height
Masks and latents are picky about dimensions. An inpainting node wants its mask to match the latent exactly, your upscaler just changed the image size, and now the mask you carefully painted is 1024×1024 sitting next to a 2048×2048 image. MaskScale is the node that resizes a MASK tensor by itself - no touching the image, no pixel-wrangling in Python, just pick a target and get the mask (and its new dimensions) back out.
What it does
You feed it a mask and one of five ways to define the target size via scale_definition:
- 宽度 (width) / 高度 (height) - pin one side, the other follows if
keep_proportionsis on. - 最长边 (longest side) / 最短边 (shortest side) - the classic "make the long edge 1024" behavior, default 最长边.
- 总像素 (total pixels) - target total area, aspect kept.
definition_value (int, default 512) is the number for whichever definition you picked. interpolation defaults to Lanczos - keep it there for masks; nearest is only worth it for hard-edged mattes where you want zero feathering. keep_proportions defaults to true, which is what you want 95% of the time.
There's also an optional width / height pair. Set both above 0 and they override the definition entirely - exact dimensions, keep_proportions gets ignored. That's the mode you use to match a known latent size.
Outputs: the resized mask, plus width and height as ints so you can wire the actual result size into whatever needs to agree with it.
Why you'd reach for it
Every time a mask needs to travel from one resolution to another. The classic case: your ImageMaskConverter produced a mask at image resolution, you ran the image through an upscaler, and now you need the mask back at the new size before feeding an inpaint pass. Or you're building a detailer-style loop where the region mask has to line up with a re-rendered latent. MaskScale is the one-node answer instead of bolting together resize+convert nodes.
It's also handy for previewing: scale a heavy mask down to a few hundred pixels, feed it to a PreviewMask, and let the canvas breathe.
Installing it
It's part of the ComfyUI-QING pack:
cd ComfyUI/custom_nodes
git clone https://github.com/GAO-SHIQING/ComfyUI-QING
cd ComfyUI-QING
python install_dependencies.py
Restart ComfyUI after. The install script pulls the usual stack (opencv-python, scipy, scikit-image, Pillow, cairosvg, openai) - most ComfyUI installs already have them. One heads-up: the README's clone command contains a GAOSHI-QING typo; the repo is GAO-SHIQING/ComfyUI-QING, and ComfyUI Manager finds the pack correctly if you search the title.
Things to know
The math is straightforward resize, so expect the same rounding behavior as any aspect-preserving scaler: definition_value is treated as the exact target for the chosen side, and the other side is computed and rounded. A couple of genuine gotchas: explicitly setting both optional width and height disables keep_proportions silently - if you want to remember the original aspect, don't set them. And scale the mask to the latent dimensions, not the image dimensions, when you're about to inpaint - latent is 8× smaller, and a mask that matches the image won't match the latent it's guiding.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — | |
| scale_definition | COMBO | 最长边 | 5 options: 宽度, 高度, 最长边, 最短边, 总像素 |
| definition_value | INT | 5121–999999999 | — |
| interpolation | COMBO | Lanczos | 4 options: 最近邻, 双线性, 双三次, Lanczos |
| keep_proportions | BOOLEAN | true | — |
| widthopt | INT | 00–999999999 | — |
| heightopt | INT | 00–999999999 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |
| width | INT | — |
| height | INT | — |