Nodes/ComfyUI-MakkiTools/ImageTPSWarp(mki-TPS图像变形)
ComfyUI Node

ImageTPSWarp(mki-TPS图像变形)

Morph one image to fit another shape with thin-plate splines

By MakkiShizu·Created about a year ago·Updated 7 months ago· 9
ImageTPSWarp(mki-TPS图像变形)
  • source_image
  • target_mask
  • source_mask
  • IMAGE
n_points150
smoothness0.1

ImageTPSWarp_makki (display name "ImageTPSWarp(mki-TPS图像变形)") is the pack's most interesting image node, and the one most people won't have a use for. It warps an image to fit a shape rather than a rectangle: you give it a source image, a target mask, and it stretches and bends the image so its content lands inside the target mask's contour. Think texture slapped onto a mask-shaped region, a logo stretched onto a surface, or a face reshaped to match a different silhouette - with smooth warping instead of a hard crop.

How it works

Thin-plate spline (TPS) warping is the classic technique for this: you sample corresponding points on two shapes and solve for a smooth mapping that bends one onto the other. Concretely, the node:

  1. Finds the largest contour in each mask (OpenCV threshold + contour detection), or uses the full image border if no source_mask is given.
  2. Samples n_points points evenly along each contour's perimeter.
  3. Aligns the two point sets robustly (it brute-force searches the best rotational shift - a "robust alignment" step the author added so it doesn't explode when the contours' starting points don't match).
  4. Fits a thin-plate-spline interpolation (via SciPy's Rbf) from source points to target points and resamples the image through it.

Output is a single warped IMAGE at the target mask's resolution.

Inputs that matter

  • source_image (required) - the image to warp.
  • target_mask (required) - the shape to warp it into. Its contour is the destination.
  • n_points - contour samples (10–500, default 150). More points = finer detail and slower solve.
  • smoothness - the TPS smoothness factor (0–10, default 0.1). Lower = hugs the contour precisely; higher = smoother but lazier. This is your main quality knob.
  • source_mask (optional) - the shape inside the source image to warp from. Omit it and the whole image warps.

The gotcha you'll actually hit: dependencies

This node needs OpenCV and SciPy, and neither is in the pack's requirements.txt. On a bare install the first run dies with an import error the moment you drag the node in. Fix:

cd ComfyUI/custom_nodes/ComfyUI-MakkiTools
pip install opencv-python scipy

(If you're on the Windows portable build, use ..\..\..\python_embeded\python.exe -m pip install opencv-python scipy.) Most ComfyUI installs already have these from other packs, so it may just work - but if it doesn't, this is why.

Installing and notes

Install the pack via ComfyUI Manager or:

cd ComfyUI/custom_nodes
git clone https://github.com/MakkiShizu/ComfyUI-MakkiTools
cd ComfyUI-MakkiTools
pip install -r requirements.txt

Restart ComfyUI. A few honest warnings: the contour approach means it wants a mask with one clean dominant shape - a mask with several disconnected blobs gets the biggest one and ignores the rest. And TPS on a 150-point contour with a high-res image can take a few seconds; that's normal, not a hang. For matching a design to a region defined by a mask, this is a genuinely rare capability to have in a vanilla node pack.

CategoryMakkiTools

Inputs (5)

NameTypeDefaultDescription
source_imageIMAGESource image to be warped 源图像,将被变形
target_maskMASKTarget mask to warp the source image to 目标遮罩,将源图像变形到此形状
n_pointsINT15010–500Number of points to sample from contours 从轮廓采样的点数
smoothnessFLOAT0.10–10Smoothness factor for TPS warping (lower = more precise to contours) TPS变形的平滑系数(越低=对轮廓越精确)
source_maskoptMASKMask for the source image (optional, if not provided, the whole image will be used) 源图像的遮罩(可选,如果不提供,将使用整个图像)

Outputs (1)

NameTypeDescription
IMAGEIMAGE