CV Affine Shape Warp
RIGID warp fitted to point correspondences (cv2.createAffineTransformer) - the counterpart of 'CV Thin Plate Spline Warp'. Where the spline BENDS the image so every control point lands exactly on its target, an affine fit has only 6 (or 4) parameters for the whole image: it keeps straight lines straight and parallel lines parallel, and solves the correspondences in the least-squares sense. That is what makes it the right tool when the correspondences are NOISY (a spline would chase every wrong match) or when the true motion really is rigid, and the wrong tool for a genuinely non-linear deformation - 'residual' is what tells the two cases apart. The shape module is a class API no raw wrapper reaches, and the classes must come from the create* factory. Unlike the spline's, this warpImage is a FORWARD warp, so one fit drives both the pixels and the points.
- image
- points_from
- points_to
- extra_points
- image
- warped_points
- residual
- matrix
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image | COMFY_MATCHTYPE_V3 | Image to warp; it is transformed so that 'points_from' move towards 'points_to'. Areas pulled in from outside the frame come out black (BORDER_CONSTANT). 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_from | NPARRAY | Nx2 control points in the INPUT image (matched keypoints, landmarks, a grid...). At least 3. | |
| points_to | NPARRAY | Nx2 target positions, row-aligned with points_from - where each control point should end up. With more than 3 rows the fit is least-squares, so they need not be reachable exactly. | |
| model | COMBO | How much freedom the fit gets. 'full affine' is the usual 6-dof least-squares affine (it can shear and scale the axes differently). 'similarity' drops shear and non-uniform scale, keeping angles and shape - a stiffer model that resists bad correspondences but cannot represent a shear at all (its residual stays large no matter how clean the points are). | |
| extra_pointsopt | NPARRAY | Optional extra Nx2 points to push through the same transform (e.g. a bounding box or contour that must follow the image). Not used to fit it. |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| image | COMFY_MATCHTYPE_V3 | The warped image, same format and size as the input. |
| warped_points | NPARRAY | Nx2 'extra_points' mapped through the transform (empty when none were connected). |
| residual | NPARRAY | Nx2 where 'points_from' actually landed minus where they should have. ~0 only when the correspondences ARE an affine (a similarity, for the 4-dof model); otherwise it is the honest least-squares error - the measure of how badly the rigid model fits. |
| matrix | NPARRAY | The fitted transform as a 2x3 float64 matrix, read back by pushing the origin and the two unit vectors through it - ready for 'cv2.warpAffine' / 'cv2.transform' or for comparing against a known pose. |