Nodes/NH-Nodes/Mask Properties (NH)
ComfyUI Node

Mask Properties (NH)

Width, height, and bbox of a mask in one pull

By jetthuangai·Created 5 months ago·Updated 21 days ago· 6
Mask Properties (NH)
  • mask
  • width
  • height
  • x1
  • y1
  • x2
  • y2
  • bbox

Mask Properties (NH) (class NH_MaskProperties) answers the question "where actually is my subject?" in one pull. Feed it a mask and it measures the bounding box of the non-empty region and hands you the numbers - width, height, and the x1/y1/x2/y2 corners - plus a ready-made bbox. In the world of mask-driven workflows, that's the difference between guessing crop coordinates and knowing them.

How it works

It takes the first mask in the input batch, thresholds it (anything above 0.5 counts as "on"), and finds the min/max row and column of lit pixels. From that it computes:

  • width / height - the size of the bounding box (in pixels).
  • x1 / y1 / x2 / y2 - the box corners, where (x1, y1) is the top-left and (x2, y2) the bottom-right, inclusive.
  • bbox - a BBOX-typed structure with the same four values, ready to plug into anything that expects a bounding box rather than four loose ints.

An empty (all-black) mask returns all zeros rather than erroring, so a missing subject degrades gracefully instead of killing the run.

Where you'd actually use it

Three classic spots. One: feed the bbox into a crop or a NH Create Box Mask-style region to clip work to the subject. Two: wire the numbers into the logic layer - width < some_threshold via a compare node is how you detect "subject too small, skip or upscale." Three: logging. If you're writing metadata or naming files by subject position, these ints are exactly what you'd want to record. It's the measurement half of the NH mask toolchain; pair it with Mask Morphology (NH) to reshape what you measured.

Installing

ComfyUI Manager → search NH-Nodes → install → restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/jetthuangai/NH-Nodes.git
cd NH-Nodes
pip install -r requirements.txt

Restart and refresh the browser page. numpy/torch only.

Gotchas

The biggest one: it only inspects the first mask of a batch, so batch workflows get one measurement, not per-item numbers - if you need per-image properties, run masks through one at a time. The 0.5 threshold means a soft, feathered mask measures smaller than a hard-edged one; blur your mask and the bbox shrinks, which is a real source of "why is my crop different" confusion. And these are mask-relative pixel coordinates, so they're only meaningful in the coordinate space of whatever produced the mask - match resolutions before trusting the numbers.

CategoryNH-Nodes/Mask

Inputs (1)

NameTypeDefaultDescription
maskMASK

Outputs (7)

NameTypeDescription
widthINT
heightINT
x1INT
y1INT
x2INT
y2INT
bboxBBOX