Get Mask Size
Read a mask's size as numbers — with a twist you should know
- mask
- width
- height
Sometimes you need a mask's dimensions as plain numbers - to size a canvas, to scale an image to match a mask, or to drive a calculation downstream. This node takes a MASK and gives you back width and height as INTs you can wire into anything. It's a small utility, and it does exactly what it says.
But there's a twist in the implementation that you genuinely need to know, because it changes what this node reports. It does not return the full dimensions of the mask tensor. It returns the size of the mask's non-zero bounding box - the smallest rectangle that contains every pixel above a tiny threshold (0.01).
Why does that matter? If your mask is a blob in the top-left corner of a 1024×1024 canvas, this node will report something like 300×250, not 1024×1024. For a full-canvas mask it matches the canvas size, so most workflows never notice. But the moment you feed it a partial mask - an inpaint region, a detected subject, a hand-drawn selection - the numbers you get are the content's footprint, not the canvas.
How it works
It reads the mask, finds every pixel above the 0.01 threshold, and computes the bounding box of those pixels. The width is x_max - x_min + 1, the height is y_max - y_min + 1. If there's nothing above the threshold, it returns (0, 0) - which is a useful "is this mask empty?" signal all on its own.
- Input:
mask(a MASK tensor). - Outputs:
width(INT),height(INT).
That's the whole node. It's the mask sibling of the pack's Get Image Size, which does the boring thing (returns the image's actual dimensions) by comparison.
Install
Part of ComfyUI-WBLESS:
cd ComfyUI/custom_nodes
git clone https://github.com/LaoMaoBoss/ComfyUI-WBLESS
restart ComfyUI, or search "ComfyUI-WBLESS" in ComfyUI Manager. No dependencies, no models.
Troubleshooting
The gotcha is the bounding-box behavior above, and it has burned people before - the pack's own changelog mentions a V2.1.1 fix for "the Get Mask Size node returning wrong dimensions in certain scenarios," which is exactly this code path being tuned. If your numbers don't match the canvas, you're not confused, you're just seeing the content's bounding box. If you need the canvas size, feed the node's companion - Get Image Size on the corresponding image - instead. And if you're using the (0, 0) empty-mask signal as a test, it works, but remember a mask that's entirely near-black but non-zero still counts as empty. For sizing operations and bounding-box math, it's a handy little number-maker - just keep the bbox behavior in the back of your head.
Inputs (1)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| width | INT | — |
| height | INT | — |