Nodes/comfyui_cv/CV Paste Through Warp
ComfyUI Node

CV Paste Through Warp

Warps an image through point correspondences and composites it onto a background - the generic 'put THIS picture THERE' step. The correspondences can come from anywhere: 'CV Annotate Correspondences' (drag them by hand, with the background loaded next to the image), 'CV Match Features', a detector, a grid. Pick the model the geometry deserves: a thin plate spline BENDS the image onto a curved or cloth-like surface, a homography handles a flat one (poster, screen, document), and affine/similarity/translation cover the rigid cases. The composite is PREMULTIPLIED, so edges do not grow the dark outline that masking-then-blending leaves on antialiased boundaries. 'CV Quad Warp' in fill mode is the 4-corner, homography-only special case of this node. Failure-tolerant: fewer correspondences than the model needs (spline 3, homography 4, affine 3, similarity 2, translation 1) or a degenerate fit passes the background through untouched with found=false and an empty mask - branch on 'found' with an if/else node.

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Paste Through Warp
  • image
  • points_from
  • points_to
  • background
  • content_mask
  • background_paintable
  • image
  • mask
  • residual
  • found
modelthin plate spline
regularization0
Categoryimage/CV/features

Inputs (8)

NameTypeDefaultDescription
imageCOMFY_MATCHTYPE_V3The picture to bend and paste. The output comes back in THIS input's format. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
points_fromNPARRAYNx2 control points in 'image' PIXEL coordinates - where each point currently is.
points_toNPARRAYNx2 target positions in 'background' PIXEL coordinates, row-aligned with points_from - where the same-numbered point must land. 'CV Annotate Correspondences' with a background connected outputs exactly this pair.
modelCOMBOthin plate splineWhich map is fitted through the correspondences. 'thin plate spline' BENDS the image so every 'from' point lands exactly on its 'to' point (3+ pairs, non-rigid - faces, cloth, anything a matrix cannot express). 'homography' is the 8-dof planar perspective map (4+ pairs; straight lines stay straight - posters, screens, documents). 'affine' is 6-dof (3+ pairs: rotation, scale, shear, translation, parallel lines stay parallel), 'similarity' 4-dof (2+ pairs: rotation, uniform scale, translation, shape preserved), 'translation' a pure shift (1+ pair). Fewer pairs than the model needs is not an error - nothing is warped and 'found' comes out false.
regularizationFLOAT00–1000000Smoothing of the SPLINE (ignored by the other models). 0 interpolates the control points EXACTLY and follows noisy correspondences faithfully; raising it trades exactness for a gentler, more rigid warp - the knob to turn when the result folds or ripples. IMAGE-SCALE DEPENDENT: cv2 adds this to the diagonal of a kernel matrix whose other entries are d^2*log(d^2) in PIXELS SQUARED, so useful values are large - on a few-hundred-pixel image 100 buys 0.1 px of give and ~1e4 is the first setting you can see. Scale it with the SQUARE of the image size.
backgroundoptNPARRAY,IMAGEThe image pasted INTO: points_to lives in its coordinates and the output is its size. Left unconnected, the image is warped within its own canvas over black, which is the plain warp. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
content_maskoptNPARRAY,MASKWhich part of 'image' is real content: white is pasted, black is not, and the mask travels through the same warp so the edge stays exact. Unconnected means all of it. A mask of a different size is resized, never rejected. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
background_paintableoptNPARRAY,MASKWhere on 'background' the paste is allowed to land - white is paintable. This is how something in the background occludes the pasted image. Unconnected means everywhere. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.

Outputs (4)

NameTypeDescription
imageCOMFY_MATCHTYPE_V3The composite, background-sized, in the 'image' input's format. The background untouched when found=false.
maskMASKWhere the warped content actually landed, after both mask gates - the alpha the composite used. All zeros when found=false.
residualNPARRAYNx2 where 'points_from' actually landed minus where it should have. ~0 for the spline at regularization 0; for the rigid models it is the honest least-squares error, i.e. how badly the model fits. Empty when found=false.
foundBOOLEANFalse when there are fewer correspondences than the model needs, or when the fit is degenerate.