Nodes/comfyui_bmab/BMAB Detection Crop
ComfyUI Node

BMAB Detection Crop

Detect in one image, crop from another

By portu-sim·Created 2 years ago·Updated 8 months ago· 124
BMAB Detection Crop
  • source
  • target
  • image
model
padding32
dilation4

Of the three detection-driven nodes in BMAB, this is the one with the least obvious mechanics from the name alone, so it's worth being upfront about what's actually going on based on its inputs: this node detects a region using one image and crops another using that detected region.

What it is and why you'd reach for it

The two-image setup (source and target) is the tell. This node is built for situations where you're detecting on one image but want the crop applied to a different one - a smaller preview or a differently-processed version of the same scene, where running detection directly on the image you actually want cropped either isn't possible or isn't reliable. Once the detector locates the region in source, the same relative area (with padding and dilation applied) gets cropped out of target and returned.

That's a genuinely useful shape when your pipeline has two versions of "the same" image at different points - say, a fast low-res pass you're happy to run detection against, and a full-resolution version you actually want the cropped result from - and you'd rather not pay the cost, or accuracy risk, of re-running detection on the heavier image.

How it works

Detection uses the same transformers-based Grounding DINO path as BMAB's other detection nodes - no extra model install required beyond what BMAB's own requirements.txt already pulls in. padding adds margin around the detected box before cropping (so you don't get an unnaturally tight crop right at the object's edge), and dilation grows the underlying detection region itself before that padding is applied.

Inputs and outputs

  • source (required) - the image detection runs against.
  • target (required) - the image the resulting crop is actually taken from.
  • model (required, dropdown) - the detection model to use, populated from whatever detection models are installed.
  • padding (default 32, range 8–128) - margin added around the detected region before cropping.
  • dilation (default 4, range 4–32) - how much to grow the detection itself before padding is applied.

Output: a single cropped image.

Installing it

Through ComfyUI Manager: search comfyui_bmab, install, restart. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/portu-sim/comfyui_bmab.git
cd comfyui_bmab
pip install -r requirements.txt

Grounding DINO detection needs transformers>=4.40.0, which BMAB's own requirements should already satisfy - no separate download. This node has no dependency on comfyui_controlnet_aux or ComfyUI_IPAdapter_plus.

Common issues

  • The transformers version conflict that hits all of BMAB's detection nodes. If this node's detection step throws an error about an unexpected keyword argument (box_threshold is the one that's been reported), your installed transformers version doesn't match what BMAB's code expects. Match it to whatever's pinned in comfyui_bmab/requirements.txt rather than assuming the newest release is safe.
  • Source and target at very different resolutions or crops of the scene. Since the detected region from source gets applied to target, a large mismatch in how the two images frame the same content can produce a crop that lands in the wrong place on target. This node assumes a reasonably consistent spatial relationship between the two.
  • Empty model dropdown. No detection model installed where BMAB expects one - check your model files against the README before assuming the node is misbehaving.
CategoryBMAB/imaging

Inputs (5)

NameTypeDefaultDescription
sourceIMAGE
targetIMAGE
modelCOMBO0 options:
paddingINT328–128
dilationINT44–32

Outputs (1)

NameTypeDescription
imageIMAGE