Nodes/ComfyuiSmartColorMatch/Cloth Texture Replace (Masked)
ComfyUI Node

Cloth Texture Replace (Masked)

Swap a garment's fabric without re-rendering — keep the pose, change the pattern

By kayorlian·Created 7 months ago·Updated 8 days ago· 2
Cloth Texture Replace (Masked)
  • model_image
  • texture_image
  • mask
  • IMAGE
texture_width_cm10.0
strength30

You've got a model shot where the outfit is great but the fabric is wrong - plain where you wanted plaid, or a pattern that doesn't match the textile a client actually sells. Re-rendering risks changing everything else, and inpainting the garment tends to drift the silhouette. Cloth Texture Replace is the 2D shortcut: it pastes your texture onto the garment, warps it to follow the lighting and folds, and - here's the good part - leaves every pixel outside the mask completely untouched.

How it works

The pipeline is worth understanding because the inputs only make sense once you do:

  1. Scale from a face. It runs MediaPipe face detection on the model photo, assumes the average face is about 15 cm wide, and converts that into pixels-per-centimeter. texture_width_cm then becomes the real-world width of one pattern repeat on the garment. No face detected? It falls back to assuming the shot is ~50 cm wide.
  2. Flatten the texture. The fabric image is divided by a heavily blurred version of itself, stripping out the lighting baked into your fabric photo so it doesn't double up with the garment's own shading.
  3. Make it seamless, then tile it to the image size (it blends a 15% overlap on the tile edges so repeats don't show).
  4. Warp it with the model's shading. Sobel gradients of the model's brightness become a displacement map, so the pattern bends around folds and highlights. strength (0–100, default 30) controls how much warp.
  5. Blend in HSV. It keeps the model's hue and saturation but replaces the value (brightness) channel with the texture's luminance. The fabric keeps the garment's color and lighting and just gains the pattern - which is why the result looks like the same garment in a different textile.
  6. Masked composite. The mask is binarized at 127 then Gaussian-feathered, and outside it the output is identical to the input.

The inputs that matter

  • model_image - your person/garment photo.
  • texture_image - the fabric swatch. Flat, evenly lit, straight-on works best; a photo with its own shadows fights the flattening step.
  • mask - the garment area. Clean edges matter a lot here (more below).
  • texture_width_cm - real-world width of one pattern repeat, default 10 cm. Bigger means fewer, larger repeats; smaller gives a tighter weave.
  • strength - how strongly the pattern warps around the model's shading, default 30.

Output is a single IMAGE, same size as the model. Wire it into a Save Image node or on into your pipeline.

Installing it

Same pack as Smart Color Match: ComfyUI Manager → search ComfyuiSmartColorMatch → Install, or clone it into custom_nodes:

cd ComfyUI/custom_nodes/
git clone https://github.com/kayorlian/ComfyuiSmartColorMatch

Then restart. This node is where the pack's heavy dependency lives: it needs mediapipe alongside numpy and opencv-python. MediaPipe wheels tend to lag the newest Python releases, so if install fails on a very fresh Python that's the usual cause - run ComfyUI's venv on a Python it actually has wheels for (3.10–3.12 has been the safe zone). MediaPipe also fetches its face-detection model on first use, so a fully offline machine needs that one-time download.

Where people get burned

  • The mask gets hard-thresholded. Soft, feathered masks get snapped to a hard edge at 127. Bring a tight, clean garment mask - hand-painted, or from SAM / BIRENet - not a rough lasso.
  • Scale depends on a detectable face. Crop the shot so the face is visible, or the 50 cm fallback guess kicks in and your texture_width_cm stops meaning anything. Test the scale on one frame before batching.
  • It's a 2D paste, not a 3D drape. The warp follows image luminance, so front-on shots with low-contrast lighting look convincingly draped, while heavy perspective or deep occlusion will look painted-on. For extreme angles you genuinely want a re-render or an inpaint/ControlNet pass instead.
  • The fabric casts no new shadows. Only the masked region is replaced, which is the whole appeal - bit-identical pixels outside the mask - but it also means the new fabric can't shade the body. Keep the source lighting soft and it won't matter.

It's a niche tool and a small pack, but for "same garment, different fabric" work it's the fastest path that doesn't touch the rest of the image.

CategoryImage/Texture

Inputs (5)

NameTypeDefaultDescription
model_imageIMAGE
texture_imageIMAGE
maskMASK
texture_width_cmFLOAT10.01–100
strengthINT300–100

Outputs (1)

NameTypeDescription
IMAGEIMAGE