Nodes/hd-nodes-comfyui/HD GetMaskArea
ComfyUI Node

HD GetMaskArea

ComfyUI Node Guide

By xiaoxiaodesha·Created 2 years ago·Updated 2 years ago· 18
HD GetMaskArea
  • image1
  • image2
  • mask
  • IMAGE
  • IMAGE
  • MASK
h_offset100
h_cutoff0.000
max_width1600
min_height2400

This is the "automatically crop the image, sized appropriately around the person" node the hd_node README name-checks as one of the pack's four headline features - it just doesn't say so by name, and the schema doesn't spell out its math either. What it does say, loud and clear, is the shape of the job: hand it two images and a mask, get back a matched pair of crops plus the mask cropped to fit. That's a familiar move if you've used any detect-crop-refine tool before - Impact Pack's Detailer, ADetailer, the newer Inpaint Crop and Stitch pattern - they all do some version of "find the interesting region, cut it out at a sane size, hand it downstream, remember how to paste it back." This node is that same idea, homemade.

Why two images, not one. The two IMAGE inputs (image1, image2) most plausibly cover a "before and after" pairing - crop the same region out of two aligned frames in one shot, so you don't have to run two separate crop nodes and hope the coordinates match. Think: the original photo and a processed version of it (post-levels, post-upscale), cropped identically so everything downstream stays in registration. Both come back out as separate IMAGE outputs, alongside a MASK output that's the input mask cropped to the same box - which is exactly what you'd need to hand to something like Cover-HDMasks later, to paste a processed crop back into the full-size canvas at the right coordinates.

The inputs that actually shape the crop. Four numbers control the sizing, and this is the part the schema is honest but sparse about - there's no tooltip explaining the exact math, so here's what the names and defaults suggest:

  • max_width (default 1600) and min_height (default 2400) - the crop's size bounds. That 2:3-ish portrait bias in the defaults lines up with "crop a person," not a landscape shot.
  • h_offset (default 100) and h_cutoff (default 0, tiny 0.001 step) - both read as vertical positioning knobs relative to wherever the mask says the subject is, most likely controlling how much headroom sits above the crop and where the bottom edge gets cut off.

Nudge max_width/min_height first if the crop is coming out the wrong overall size; touch h_offset/h_cutoff if the size is right but the framing is off - too much empty space above the head, or the crop cutting off too high or low. That's an honest "here's where to start," not a guarantee of the exact formula underneath - the README doesn't document this node individually, and there's no source to lift the precise math from.

Installing it. Same pack-wide steps as the rest of hd_node: search "hd-nodes-comfyui" or "HD Nodes" in ComfyUI Manager, or cd ComfyUI/custom_nodes && git clone https://github.com/xiaoxiaodesha/hd_node, then restart. This node itself does no face detection, but the pack won't fully register without insightface installed in ComfyUI's Python environment either way - the README's install note isn't scoped to just the node that needs it, and a failed import at load time can take the whole pack's node list down with it. The HD-FaceIndex article in this series covers that install in detail if you hit it.

Troubleshooting. With no documented formula and no community discussion to lean on, the practical approach is empirical: run it on a couple of test images with different subject positions and framing, watch how the crop shifts as you move each of the four numbers, and lock in values that work for your source material rather than expecting one setting to generalize. If the crop comes back empty or absurdly small, check the mask feeding in first - a mostly-empty or disconnected mask is the most common reason any mask-driven crop node produces garbage, and it's worth ruling out before you start second-guessing the offset math.

CategoryHD Nodes

Inputs (7)

NameTypeDefaultDescription
image1IMAGE
image2IMAGE
maskMASK
h_offsetINT100
h_cutoffFLOAT0.000
max_widthINT16000–16384
min_heightINT24000–16384

Outputs (3)

NameTypeDescription
IMAGEIMAGE
IMAGEIMAGE
MASKMASK