Nodes/comfyui_bmab/BMAB Detect And Paste
ComfyUI Node

BMAB Detect And Paste

Find a region, drop another image into it

By portu-sim·Created 2 years ago·Updated 8 months ago· 124
BMAB Detect And Paste
  • image
  • source
  • image
model
dilation4
threshold0.35
sam_masking

This node combines two things BMAB does separately elsewhere - detection and compositing - into one step. Instead of detecting a mask and then wiring it into a separate paste/composite node, this does both in one pass.

What it is and why you'd reach for it

You give it two images - the one you're detecting in, and a source you want composited into whatever gets detected - plus a detection model, and it finds the target region and pastes the source into it. This is a step up in convenience from chaining BMAB Detect And Mask into BMAB Alpha Composit by hand: one node, one detection pass, one paste. It's the node to reach for when you know the target region needs to come from an automatic detector rather than a hand-painted mask - swapping a detected object for a different image, region-based compositing across a batch, or any workflow where you don't want to paint a mask for every input image individually.

The sam_masking toggle is worth understanding before you assume this node behaves identically with it on or off: with SAM masking enabled, the raw detection box gets refined into a tighter, actual-shape segmentation mask (the same GroundingDINO-plus-SAM pattern used across the ecosystem for precise, non-rectangular selections) rather than a plain bounding box. That's the difference between a clean edge that follows the object's actual silhouette and a compositing result that visibly pastes a rectangle.

How it works

Detection runs on transformers' Grounding DINO implementation, the same mechanism BMAB Detect And Mask uses - no separate model install needed for that specific piece. threshold is the detection confidence cutoff: raise it if the detector is finding false positives, lower it if it's missing the thing you actually want. dilation grows the resulting mask slightly, same purpose as everywhere else in BMAB - softening the seam where the pasted content meets the rest of the image.

Inputs and outputs

  • image (required) - the image to detect a region in.
  • source (required) - the image to paste into that detected region.
  • model (required, dropdown) - the detection model to run. Populated from whatever detection models you have installed.
  • dilation (default 4, range 4–128) - how much to grow the detected mask before pasting.
  • threshold (default 0.35, range 0–1) - detection confidence threshold.
  • sam_masking (required, enum: off / on) - whether to refine the detection into a precise SAM-style segmentation mask rather than a plain box.

Output: a single composited 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

Detection rides on transformers>=4.40.0, already part of BMAB's own requirements - no separate Grounding DINO download needed. This node doesn't require comfyui_controlnet_aux or ComfyUI_IPAdapter_plus.

Common issues

  • The known transformers version conflict. BMAB's Grounding DINO detection path has a documented compatibility problem where a mismatched transformers version throws something like GroundingDinoProcessor.post_process_grounded_object_detection() got an unexpected keyword argument 'box_threshold'. If this node's detection step errors out with a complaint about an unexpected keyword argument, match your installed transformers version to what's pinned in comfyui_bmab/requirements.txt rather than assuming the newest release will work.
  • Threshold set too high or too low. A high threshold can mean the detector finds nothing at all and the paste silently fails to apply anywhere meaningful; too low, and you'll get false-positive detections in the wrong spot. 0.35 is a reasonable starting point, but tune it against your specific detector and target object.
  • Visible rectangular paste edges. If your composited result looks like a box was pasted in rather than a naturally-shaped object, turn sam_masking on to get a real segmentation mask instead of a bounding-box paste, and consider raising dilation slightly for a softer edge.
CategoryBMAB/imaging

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
sourceIMAGE
modelCOMBO0 options:
dilationINT44–128
thresholdFLOAT0.350–1
sam_maskingCOMBO2 options: off, on

Outputs (1)

NameTypeDescription
imageIMAGE