๐บโโข Convert mask to rectangle
Turn a messy mask into a clean box
- mask
- MASK
A quick heads-up before anything else: this node is newer than what the pack's own README has caught up to documenting, so there's no author write-up to lean on here. What follows is read straight off the node's actual inputs and outputs - a solid mask-in, mask-out utility, and the name plus the four directional parameters make the job pretty unambiguous.
What it does
Feed it an irregular mask - the kind of blob shape you get out of a segmentation node, a hand-painted mask, or a detector's SAM output from something like Impact Pack - and it collapses that shape down to its bounding rectangle: the tightest solid box that fully contains the masked region. That's the core move, and it's a common step before an inpaint or crop pass, where you often want a clean rectangular region rather than the ragged edge a detector actually gave you.
The inputs that matter
Alongside the required mask, you get four integer offsets - up, down, left, right - each ranging from -10000 to 10000 with a default of 0. These push the edges of the resulting rectangle outward (positive values) or inward (negative values) from wherever the tight bounding box would naturally land. Practically: if your detected region is a bit too tight around a face or object and you want breathing room before you crop or inpaint, bump up/down/left/right up a bit. Want a smaller box than the raw detection gave you, shrink them into negative territory.
The single output is a MASK - the new rectangular region, ready to feed into a crop, an inpaint node, or the pack's own Cut Image with Mask.
Installing it
Through ComfyUI Manager: search Bjornulf_custom_nodes, install, restart. Or by hand:
cd ComfyUI/custom_nodes
git clone https://github.com/justUmen/Bjornulf_custom_nodes
Install the pack's shared dependencies afterward - pip install -r requirements.txt inside that folder on Linux, or the Windows embedded-python equivalent listed in the repo's README. This particular node doesn't need any of the heavier video/TTS/API dependencies to function; it's pure image-processing math, so it'll work even if you skip installing everything else the pack pulls in.
Where people get burned
The main trap with any bounding-rectangle-from-mask tool: if your input mask has more than one disconnected blob in it (two separate detected regions, say), a single bounding rectangle will span both of them and everything in between - which is rarely what you actually wanted. Check your mask is a single contiguous region before feeding it in, or split multi-region masks upstream first. Beyond that, because this node isn't in the README yet, if its exact behavior around edge cases (masks touching the image border, fully empty masks) surprises you, that's genuinely unverified territory - test it on your actual input before building a big workflow around it.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| mask | MASK | โ | |
| up | INT | 0-10000โ10000 | โ |
| down | INT | 0-10000โ10000 | โ |
| right | INT | 0-10000โ10000 | โ |
| left | INT | 0-10000โ10000 | โ |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| MASK | MASK | โ |