BMAB Detect And Paste
Find a region, drop another image into it
- image
- source
- image
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
transformersversion conflict. BMAB's Grounding DINO detection path has a documented compatibility problem where a mismatchedtransformersversion throws something likeGroundingDinoProcessor.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 installedtransformersversion to what's pinned incomfyui_bmab/requirements.txtrather than assuming the newest release will work. - Threshold set too high or too low. A high
thresholdcan 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_maskingon to get a real segmentation mask instead of a bounding-box paste, and consider raisingdilationslightly for a softer edge.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| source | IMAGE | — | |
| model | COMBO | 0 options: | |
| dilation | INT | 44–128 | — |
| threshold | FLOAT | 0.350–1 | — |
| sam_masking | COMBO | 2 options: off, on |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |