LanPaint Image Encode
Setting up a LanPaint inpaint
- image
- vae
- mask
- latent
If you've inpainted in ComfyUI, you know the ritual: VAEEncode the image, shove the mask through SetLatentNoiseMask, and silently pray the mask actually lines up with what the VAE did to the pixels. LanPaint_ImageEncode collapses that whole chain into a single node - and it fixes the alignment problem while it's at it.
This is the encode half of the LanPaint pipeline. LanPaint itself is a training-free inpainting sampler - a Langevin-dynamics "thinking" sampler, peer-reviewed and published in TMLR 2025 (arXiv 2502.03491) - that adds reasoning iterations before each denoising step so almost any model can do masked inpainting without a dedicated inpaint checkpoint. This node is the boring, dependable front end: it takes the image you want to inpaint and hands the sampler a latent that already knows where to regenerate.
What it actually does
The mechanism matters because of a classic ComfyUI gotcha. A VAE doesn't divide your image into a clean grid - its padding can leave the latent a pixel or two off from the mask, which is how you get inpainted results that look right in the preview and wrong in the final stitch. LanPaint_ImageEncode encodes the image, then snaps your mask to the latent's actual spatial size using nearest-exact interpolation. Whatever the VAE's padding did, the mask always matches, and the mask rides inside the latent as a noise_mask (the same convention SetLatentNoiseMask uses).
It's also a little more general than you'd expect. Hand it a plain image VAE and you get a normal 4D latent. Hand it a 5D video-style VAE (say, the Hunyuan video VAE encoding a single image) and it attaches one mask slice per latent frame instead of crashing. Without a mask it just... encodes. No surprise behavior.
The inputs that matter
- image - what you're inpainting. The mask's "1 = regenerate" region gets new content; everything else is preserved.
- vae - the model's VAE. Match it to the checkpoint you'll sample with.
- mask (optional) - your inpainting mask, [H, W]. Snapped to the latent size automatically, so don't sweat resolution.
Output is a single latent, which you wire straight into a LanPaint KSampler (or any sampler that respects a noise mask).
Installing
It ships with the whole LanPaint pack, so install the pack: ComfyUI Manager → search "LanPaint", or clone it yourself:
cd ComfyUI/custom_nodes
git clone https://github.com/scraed/LanPaint
then restart ComfyUI. No pip dependencies come with the pack (its pyproject.toml declares none), and it requires ComfyUI newer than 0.3.11. The LanPaint samplers show up under "sampling"; this encode node lives in the image category alongside it.
Where people get burned
The mask must be effectively binary - values of 0 or 1. The LanPaint README is explicit: set opacity and hardness to maximum in whatever painted the mask, because the sampler converts anything smooth to binary anyway. And remember the direction of the convention: 1 = regenerate, 0 = keep, the opposite of some other tools. If you get the mask inverted you'll "inpaint" the entire background instead of the one object you circled - which, to be fair, is a great way to learn what this node does.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | The image to encode (1 = regenerate region comes from the mask). | |
| vae | VAE | The VAE. | |
| maskopt | MASK | Inpainting mask [H, W] (1 = regenerate, 0 = keep). Snapped to the latent size automatically. |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| latent | LATENT | — |