Nodes/Eden.art nodesuite/Mask Bounding Box Crop
ComfyUI Node Runs on cloud

Mask Bounding Box Crop

Crop to your mask automatically — it hands back the cropped image AND the box coordinates

By edenartlab·Created 3 years ago·Updated 10 days ago· 120
Mask Bounding Box Crop
  • mask
  • image_optional
  • MASK
  • IMAGE
  • x
  • y
  • width
  • height
◄padding0►
◄blur0►
◄noise_threshold1►

Eden_MaskBoundingBox finds the tight rectangle around everything bright in your mask, crops the mask (and optionally the matching image) to that box, and reports the box's x, y, width, and height. It's the "focus the generation budget where the mask is" node - the workhorse behind crop-and-upscale detail passes, where you render a small region at full resolution instead of the whole frame.

How it works

The pipeline is four steps. First, a noise-reduction pass: it runs max-pooling over the mask and keeps only pixels that have at least noise_threshold non-zero neighbors - a cheap way to kill specks and stray bright pixels before the bounding box is computed. Second, an optional Gaussian blur on the mask (blur pixels), which makes the crop region bleed outward into soft territory and is often what you want before an inpaint so the seam isn't razor-sharp. Third, it finds the min/max coordinates of the remaining bright region and expands them by padding. Fourth, it crops both the mask and the image (if you passed image_optional) to that box.

The outputs are the real value here. You get the cropped MASK, the cropped IMAGE (or a grayscale version of the mask if you passed no image), and the x, y, width, height of the crop in the original frame. Those four ints let a downstream composite node put the result back exactly where it came from.

Inputs

  • mask (MASK) - what to bound.
  • padding (default 0, 0–4096) - extra room around the box.
  • blur (default 0, 0–256) - Gaussian blur applied to the mask before bounding.
  • noise_threshold (default 1, 0–1000) - minimum non-zero neighbors a pixel needs to survive noise removal.
  • image_optional (IMAGE) - the matching image to crop alongside the mask.

Outputs: MASK, IMAGE, x, y, width, height.

Where it fits

Mask-guided upscaling is the classic loop: mask a face, get its bounding box, crop the region, run the sampler on the crop at native resolution, then composite the result back using the box coordinates. In a world where whole-frame editing has mostly taken over, this is still the way to do high-detail regional fixes - the KB's inpainting notes make the same point: crop a small region, render it big, paste it back. The box outputs are exactly the "paste it back" data.

Installing it

Part of the Eden.art nodesuite. Install via ComfyUI Manager (search "Eden.art nodesuite") or:

cd ComfyUI/custom_nodes
git clone https://github.com/edenartlab/eden_comfy_pipelines
cd eden_comfy_pipelines && pip install -r requirements.txt

Restart ComfyUI.

Common issues

If the mask is empty (all black), the node returns the entire image as the box rather than erroring - good behavior, but easy to misread as a bug. A high noise_threshold can eat genuine mask detail, so keep it low (1–3) unless you're fighting noise. And remember blur applies before the box is computed, so a big blur makes the box bigger - that's usually the desired feather, just know it's happening.

CategoryEden 🌱/Mask

Inputs (5)

NameTypeDefaultDescription
maskMASKMask whose non-zero region defines the crop.
paddingINT00–4096Extra pixels added around the bounding box.
blurINT00–256Gaussian blur kernel size applied to the mask before finding the box (0 = off).
noise_thresholdINT10–1000Minimum number of non-zero pixels in a 3x3 neighbourhood for a pixel to survive denoising.
image_optionaloptIMAGEImage to crop with the same box; resized to the mask if needed. Defaults to the mask itself.

Outputs (6)

NameTypeDescription
MASKMASKCropped mask.
IMAGEIMAGECropped image.
xINTLeft edge of the box.
yINTTop edge of the box.
widthINTBox width.
heightINTBox height.