Nodes/ComfyUI CV/CV Paste by BBox
ComfyUI Node

CV Paste by BBox

Put the crops back where they came from — no policy, no fuss

By bmad4ever·Created 3 months ago·Updated 14 days ago· 1
CV Paste by BBox
  • image
  • crops
  • bboxes
  • masks
  • image
◄feather0.0►

Crop, process, paste home. That's the shape of nearly every detail-and-inpaint workflow - cut the face out, run something on it, put it back - and the "put it back" step is where people lose an afternoon. The bboxes you cropped with were snapped by a crop policy (padded, squared, rounded to a multiple), so pasting with your original coordinates lands everything a few pixels off.

CV Paste by BBox is the inverse of CV Crop by BBoxes / CV Crop by Masks, and it's built to be fed the crop node's own bboxes output - the snapped boxes - so the geometry lines up by construction. It needs no policy because it isn't computing anything: it flattens whatever shape the crop node emitted, pairs crop i with box i, and writes the values back through.

The clever bit is doing nothing

It works in the target's own type - IMAGE, MASK, NPARRAY or LATENT - and writes values through untouched. An unmodified crop round-trips exactly, which is the property you want when the thing you're debugging is a color shift three nodes downstream. If a latent-space edit paste were going to introduce a VAE round trip, you'd never be able to tell your problem from the node's.

It also accepts both output shapes the crop nodes can produce (one stacked batch, or one item per region) and figures out the pairing itself, so you don't have to know which mode your crop node was in.

Inputs and the one knob

  • image - what to paste into. Frame 0 is used.
  • crops - the crop node's crops output. Must be the same type as image.
  • bboxes - the crop node's bboxes output, one per crop, in the same order.
  • feather - Gaussian blur sigma applied to the paste masks. 0 gives a hard rectangular seam; a few pixels of feather hides a slightly-off crop, and more makes an obvious vignette. Small values only; this is a seam softener, not a blend mode.
  • masks (optional) - crop-space masks, white = paste. This is how you paste only the masked region instead of the whole rectangle, and it's the difference between "pasted a rectangle" and "composited a subject".

Output is image, the target with every crop pasted in, in its own type.

The workflow it lives in

The canonical shape: detect → CV Snap BBoxes (Crop Policy) → CV Crop by BBoxes → whatever you're doing to the crops (a sampler pass, a color match, an upscale) → paste back. Pair it with CV Photometric Align (Gain/Bias) before pasting and the patched region matches the surrounding exposure instead of standing out as a bright rectangle. Pair it with a soft masks input and you've got a hand-rolled detailer.

Because the crop/paste geometry in this pack is implemented in pure Python + numpy rather than being a cv2 call, the crop half is where the pack author explicitly warns that the example workflows are tuned to specific datasets - the nodes are general, the demo graphs are not.

Install

Manager → search ComfyUI CV, or:

cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_cv
cd comfyui_cv && pip install "opencv-contrib-python-headless~=5.0.0.93"

Restart. Python ≥ 3.12 and the V3 node API. The example workflows that use the crop/paste family load their sample media from example_inputs/ - run workflows/01_install_example_inputs.json once (a single node, nothing to wire) and reload the ComfyUI page, because the Load Image dropdowns are built when node definitions are fetched.

Common issues

  • Crops land in the wrong places - you're pasting with your own original boxes instead of the crop node's snapped bboxes output. Always use the one the crop node emitted.
  • Crops land in the wrong order - crops and bboxes came from different crop nodes, so index i no longer means the same region.
  • A visible rectangular seam - raise feather a couple of pixels, or supply masks so only the subject is pasted.
  • Type mismatch errors - crops and image must be the same container type; don't crop from an IMAGE and paste into a LATENT.
  • Example workflows open with red Load Image nodes - you haven't run the example-inputs installer, or you didn't refresh the page after running it.

Usual pack caveat: heavy LLM assistance, not production-verified, updates whenever. The paste geometry here is simple enough to eyeball on one crop before you trust it on a batch.

Categoryimage/CV

Inputs (5)

NameTypeDefaultDescription
imageCOMFY_MATCHTYPE_V3What to paste into. Frame 0 is used; the crops must be the same type.
cropsCOMFY_MATCHTYPE_V3The crop node's 'crops' output, in either shape.
bboxesBOUNDING_BOX[object Object]Core BOUNDING_BOX data: per-frame lists of {x, y, width, height} dicts - compatible with Draw BBoxes, Crop By Bounding Boxes, Image Crop, etc. The crop node's 'bboxes' output (the SNAPPED boxes) - one per crop, in the same order.
featherFLOAT0.00–100Gaussian blur sigma applied to the paste masks for soft seams.
masksoptMASKOptional crop-space masks (white = paste); the full rectangle is pasted if omitted.

Outputs (1)

NameTypeDescription
imageCOMFY_MATCHTYPE_V3The target with every crop pasted in, in its own type.