Nodes/ComfyUI-NKD-VFX-Tools/😺NKD Perspective Unwarp
ComfyUI Node

😺NKD Perspective Unwarp

Flatten the Poster Before You Inpaint It

By Nekodificador·Created 6 months ago·Updated a day ago· 155
😺NKD Perspective Unwarp
  • image
  • image
  • warp_data
â—„corners{"corners": [[0.15, 0.15], [0.85, 0.2], [0.8, 0.85], [0.2, 0.8]]}â–º
â—„aspect_sourceAutoâ–º
â—„manual_ratio_w1.00â–º
â—„manual_ratio_h1.00â–º
â—„resolution_modeLongest Sideâ–º
â—„longest_side1024â–º
â—„megapixels1.00â–º
â—„focal_length_mm35.0â–º

Want to replace the text on a poster that's hanging at an angle in a photo? Inpaint it in place and you're asking the model to draw text in perspective, which diffusion does badly - it mangles the letterforms because it's fighting the foreshortening at the same time. Flatten the region first and all it has to draw is flat text, which it does well. Perspective Unwarp is the flattening step: you drag the four corners of the region and it warps that quad to a fronto-parallel image, ready to paint or inpaint.

How it works

Four corners in, one homography out. The node solves the 3×3 homography mapping your quad to a rectangle (a DLT solve via SVD - this is the standard four-point perspective correction, the same math photo editors have used for thirty years), then samples the image through it with torch.grid_sample. The core path needs no OpenCV at all, which is rare for a geometry node and worth appreciating.

The interesting bit is aspect_source. "Auto" estimates the aspect ratio from the quad's own edges, which is a guess. "Metric" uses a real focal length - wire in focal_length_mm from NKD fSpy Camera and the flattened output comes out at the region's true aspect ratio instead of an estimate. That's the difference between a flat version that looks right and one that's measurably correct, and it's free once you've already solved the camera. "Manual" just uses the ratio you type.

Resolution is controlled through resolution_mode: "Longest Side" (default 1024) or megapixels, so you can decide whether the flattened region has enough pixels for a full-res inpaint.

The inputs that matter

  • image - the photo.
  • corners - the quad, as JSON. Again, you won't type this: you drag the corners on the node's viewport, and the widget stores the result so it survives a workflow save.
  • aspect_source - Auto / Metric / Manual. Pick Metric if you have a focal length to wire in.
  • focal_length_mm (optional) - the fSpy output for Metric mode. 0 falls back to Auto.

Outputs: image (the flattened, fronto-parallel region) and warp_data (NKD_WARPDATA) - connect that cable to NKD Perspective Rewarp to put your edit back at the original angle.

Install and the wider loop

Same as the whole pack: ComfyUI Manager, search "NKD VFX Tools", restart. No models. The full loop is Unwarp → edit flat (inpaint, img2img, whatever) → Rewarp, and the geometry goes back exactly as it was. This is the node that makes "draw me a poster" actually usable on real footage instead of a lottery.

Category😺NKD Nodes/3D

Inputs (9)

NameTypeDefaultDescription
imageIMAGE—
cornersSTRING{"corners": [[0.15, 0.15], [0.85, 0.2], [0.8, 0.85], [0.2, 0.8]]}—
aspect_sourceCOMBOAutoAuto: estimate from the quad edges. Metric: true aspect from a connected focal length (fSpy). Manual: use the ratio below.
manual_ratio_wFLOAT1.000.01–100—
manual_ratio_hFLOAT1.000.01–100—
resolution_modeCOMBOLongest Side2 options: Longest Side, Megapixels
longest_sideINT102416–8192—
megapixelsFLOAT1.000.05–16—
focal_length_mmoptFLOAT35.00–100035mm-equivalent focal length for Metric mode (defaults to a 35mm lens). Wire this from 😺NKD fSpy Camera's focal output for a real solve. 0 falls back to Auto.

Outputs (2)

NameTypeDescription
imageIMAGEThe flattened, fronto-parallel region.
warp_dataNKD_WARPDATAConnect to 😺NKD Perspective Rewarp.