Nodes/ComfyUI-TextureAlchemy/Patch Fit ๐Ÿ“ฆ
ComfyUI Node

Patch Fit ๐Ÿ“ฆ

The other half of the crop-upscale-inpaint-stitch workflow

By amtarrยทCreated 9 months agoยทUpdated 4 months agoยท 58
Patch Fit ๐Ÿ“ฆ
  • image
  • scale_data
  • mask
  • fitted_image
  • fitted_mask
  • info
โ—„downscale_methodareaโ–บ

Patch Upscale gives the inpainter more pixels; Patch Fit is what brings the result home. It takes the processed (and now larger) patch, reads the scale data that Patch Upscale recorded, and shrinks it back to the exact original dimensions so you can stitch it into the texture without misalignment. The two nodes are a matched pair - you rarely want one without the other.

The pattern is the standard trick for texture seam repair: crop the seam region, upscale it so Stable Diffusion has real resolution to work with, inpaint, then downscale back to the original size and composite. Do this by hand and you'll spend all your time tracking original dimensions and scale factors. Patch Fit exists precisely so you don't have to - the PATCH_SCALE_DATA object carries that bookkeeping for you.

How it works

You feed it the processed image plus the scale_data from Patch Upscale. It reads the original and upscaled dimensions out of that data and runs F.interpolate back down to the original size. Masks travel along too: pass a mask in and you get a fitted_mask back, so your inpaint region stays in sync. The default downscale_method is area, and that default is correct - area averaging is the right choice for shrinking, since bicubic can introduce ringing at texture scale.

The inputs

  • image - the processed/upscaled patch.
  • scale_data - required, and it must come from Patch Upscale. This is the one input you can't improvise.
  • downscale_method - bicubic, bilinear, lanczos, or area. Leave it on area.
  • mask (optional) - downscaled alongside the image.

Outputs: fitted_image, fitted_mask, and an info string confirming the target size.

The trap

If you disconnect the scale_data wire and reconnect it later from a fresh Patch Upscale, the stored original size is now wrong and Patch Fit will happily downscale to the wrong dimensions. It does print a warning when the current image size doesn't match the expected upscaled size, so watch the console - a mismatched fit almost always shows up as "Expected Xร—Y, got Wร—H" in the log. Also note that if your inpaint changed the image dimensions (some pipelines crop for speed), Patch Fit warns but continues, and the fit will be off. Keep the chain linear: crop โ†’ Patch Upscale โ†’ inpaint at the same size โ†’ Patch Fit โ†’ stitch.

Installation

Part of amtarr/ComfyUI-TextureAlchemy, under Add Node โ†’ Texture Alchemist โ†’ Inpainting. Install via ComfyUI Manager (search "TextureAlchemy") or:

cd ComfyUI/custom_nodes
git clone https://github.com/amtarr/ComfyUI-TextureAlchemy

Restart ComfyUI. No dependencies beyond ComfyUI's bundled torch - nothing to pip-install, no models to fetch.

CategoryTexture Alchemist/Inpainting

Inputs (4)

NameTypeDefaultDescription
imageIMAGEโ€”
scale_dataPATCH_SCALE_DATAโ€”
downscale_methodCOMBOareaInterpolation method for downscaling (area is best for downscaling)
maskoptMASKOptional mask to downscale with image

Outputs (3)

NameTypeDescription
fitted_imageIMAGEโ€”
fitted_maskMASKโ€”
infoSTRINGโ€”