Nodes/ComfyUI_Gayrat/GF Fill BBox
ComfyUI Node

GF Fill BBox

Turn a mask's bounding box into a filled mask and a blue-box preview

By gayratv·Created about a year ago·Updated about a year ago· 3
GF Fill BBox
  • image
  • mask
  • filled_mask
  • image_with_fill
  • image_with_bbox
extend_to_bottomfalse
thickness3
fill_opacity0.50

If you've ever used an object detector or a segmentation model, you know the shape of the problem this node is solving: the model gives you a mask that hugs the subject, but what a lot of downstream tools actually want is the bounding box around it. GF Fill BBox takes an image and a mask, finds the smallest rectangle that contains all the mask's contours, and gives you three things: the box as a filled mask, the image with the box filled in as a semi-transparent blue overlay, and the image with just a blue outline drawn on it.

The "GF" is the author's shorthand (the source file is literally commented "GOS node"), and it's part of the same personal grab-bag pack as the rest - a small OpenCV utility, not a polished release. It's the kind of node you reach for when you're building a detection→crop→process pipeline and need to visualize or hand off the box.

Inputs

  • image and mask - required.
  • extend_to_bottom (boolean, default off) - stretch the box down to the bottom edge of the image. Useful when the mask doesn't reach the ground plane but you want the whole column filled.
  • thickness (1–20, default 3) - line width of the outline-only preview.
  • fill_opacity (0.0–1.0, default 0.5) - how strong the blue fill is in the overlay image.

Outputs

  • filled_mask - the box rendered as a solid white rectangle on the mask canvas. This is the output that matters for real work: feed it to a crop, an inpaint encode, or a compositing step that wants a rectangular region.
  • image_with_fill - the original with a translucent blue rectangle over the box. For eyeballing coverage.
  • image_with_bbox - the original with only the blue outline. The classic detector-visualization look.

The box color is hard-coded blue ((255,0,0) in BGR) - there's no color input, so don't go looking for one.

How it works, and honest caveats

It's OpenCV under the hood: findContoursboundingRect over the combined contours. No contour, no work - if the mask is empty it passes everything through unchanged. The mechanism is worth one caveat: it draws the axis-aligned bounding box of all contours combined, so a mask with two disconnected blobs gets one big box around both, not two boxes. If you need per-object boxes you'd use an Impact Pack SEGS pipeline instead (which does exactly that and more - see the detection/detailing docs). This node is for the quick, single-region case.

Also note it runs on the CPU with numpy/OpenCV and reshapes via .squeeze(0), so it assumes single-image, batch-1 inputs. If you wire a batched tensor through, the math gets weird. Keep it on one image at a time.

Install

ComfyUI Manager: search ComfyUI_Gayrat. By hand:

cd ComfyUI/custom_nodes
git clone https://github.com/gayratv/ComfyUI_Gayrat
cd ComfyUI_Gayrat
pip install -r requirements.txt

Restart ComfyUI; it's under Gayrat/Mask Processing. The pack's requirements don't list OpenCV explicitly, so it relies on the cv2 that ships with ComfyUI itself - if you hit an ImportError on cv2, pip install opencv-python-headless fixes it.

CategoryGayrat/Mask Processing

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
maskMASK
extend_to_bottomBOOLEANfalse
thicknessINT31–20
fill_opacityFLOAT0.500–1

Outputs (3)

NameTypeDescription
filled_maskMASK
image_with_fillIMAGE
image_with_bboxIMAGE