RemapFromQuadrilateral (homography)
Straighten the tilted document, screen, or sign
- src_mask_with_4_points
- REMAP
This is the sibling of RemapToQuadrilateral, and it does the reverse trick: instead of warping a flat image into a tilted quadrilateral, it takes a tilted quadrilateral and flattens it back into a rectangle. Photograph a document at an angle, outline it, and this node produces a clean, front-on version. Same idea for photographed screens, signs, or anything flat that the camera wasn't square to.
The "(homography)" in the name is doing real work. Unlike RemapToQuadrilateral, which offers three mapping modes, this node is homography-only - a proper projective transform computed with getPerspectiveTransform from your four corners to the target rectangle. That's exactly what perspective correction needs, so you're not missing anything by not having the other modes.
How the quadrilateral is defined
Same convention as its sibling: src_mask_with_4_points is a MASK containing exactly four white blobs. Each blob's centroid becomes one corner of the quadrilateral. The corners are ordered top-to-bottom, then left-to-right, and the node maps them to the four corners of the output rectangle. The workflow: grab the image, paint four dots at the corners of the region, feed the mask in.
The two numbers you actually set are width and height - the dimensions of the flattened output (defaults 512 each, range 16–4096). These define both the size and the aspect ratio of the straightened rectangle, so pick them to match the real-world shape you're correcting. A page is roughly width = 0.7 × height; a 16:9 screen should be 16:9, or you'll stretch it.
Wiring it up
RemapFromQuadrilateral (homography) produces a REMAP descriptor - the recipe, not the result. Send it into the Remap node (Bmad/CV/Transform) along with the source image and an interpolation setting. Remap performs the warp and crops to the width/height you chose. If you also want the region's mask flattened, feed one into Remap's optional src_mask; with output_with_alpha on, you get the corrected image with the corrected mask as its alpha channel, ready to composite.
Install
Part of 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. This one leans hard on OpenCV (opencv-python~=4.8.1.78 in requirements.txt), so make sure Manager or pip actually installed it. No models needed.
Gotchas
The same four-blobs rule as its sibling: touching dots merge centroids and your quad collapses, so keep the dots separate and near the actual corners. And remember the ordering assumption - if the region you outline is upside-down or mirrored relative to what the node expects, the flattening comes out rotated. When in doubt, start with HOMOGRAPHY-style workflows (that's all this node does) and check the aspect-ratio advice above before blaming the transform.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| src_mask_with_4_points | MASK | — | |
| width | INT | 51216–4096 | — |
| height | INT | 51216–4096 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| REMAP | REMAP | — |