RemapToQuadrilateral
Perspective-paste one image onto any tilted surface
- dst_mask_with_4_points
- REMAP
This is the node you reach for when you want to paste an image onto a surface that isn't flat-on to the camera - a picture onto a wall shot at an angle, a screen onto a photographed monitor, a design onto a tilted billboard. It's the "into the perspective" half of the pack's quadrilateral remap pair, and it's genuinely one of the more impressive things this grab-bag pack does.
The trick is that the node doesn't warp anything yet. It defines where in the target image the warp should land, then hands the actual warping job to a separate Remap node. RemapToQuadrilateral's output is a REMAP descriptor - think of it as a pre-computed recipe that says "warp incoming pixels into this region, this way."
How the quadrilateral is defined
You don't type coordinates. You feed it a MASK - dst_mask_with_4_points - that contains exactly four white blobs, one in each corner of the region you want. The node finds each blob's centroid and treats those four points as the corners. So the workflow is: draw a rough black mask, paint four small white dots (or circles) at the four corners, feed that in.
The mode dropdown picks the mapping math:
- HOMOGRAPHY - a proper projective transform (OpenCV's
warpPerspective). The realistic one for flat surfaces shot at an angle. This is what you'll use 99% of the time. - LENGTH-WISE and W-EDGE-PAIR - interpolation-based mappings between opposite edges. Cheaper, different distortion character; mostly for stylized/curved tricks rather than convincing perspective.
Wiring it up
RemapToQuadrilateral → Remap (also in Bmad/CV/Transform) → done. The Remap node takes your actual source image, an interpolation setting, an optional mask, and applies the recipe. Its output is the image warped into the quadrilateral (plus the remapped mask). If you set output_with_alpha, the mask comes back embedded as an alpha channel - handy for compositing the pasted region without cutting it out again.
Install
Ships in bmad4ever/comfyui_bmad_nodes. ComfyUI Manager → search comfyui_bmad_nodes, or:
cd ComfyUI/custom_nodes
git clone https://github.com/bmad4ever/comfyui_bmad_nodes
cd comfyui_bmad_nodes
pip install -r requirements.txt
Restart. The pack's requirements pin opencv-python~=4.8.1.78 (this is an OpenCV-heavy node) plus scikit-image and friends; no model files.
Gotchas
The four-blobs rule is the thing that bites. If two dots touch, their centroids merge and you get three corners - and the quad silently collapses. Keep them separate, roughly centered on the corners, and check the ordering: the node sorts corners top-to-bottom then left-to-right, so mirrored/rotated arrangements won't do what your intuition says. Also note this is the "to" direction - from a rectangle onto the quad. For the reverse (straightening a photographed document back to flat), that's its sibling RemapFromQuadrilateral.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| dst_mask_with_4_points | MASK | — | |
| mode | COMBO | HOMOGRAPHY | 3 options: HOMOGRAPHY, LENGTH-WISE, W-EDGE-PAIR |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| REMAP | REMAP | — |