Nodes/ComfyUI/Set Latent Noise Mask
ComfyUI Node Runs on cloud

Set Latent Noise Mask

The node that actually makes ComfyUI inpaint

By Comfy-Org·Created 4 years ago·Updated about 19 hours ago· 130,493
Set Latent Noise Mask
  • samples
  • mask
  • LATENT

Every "fix this one part of the image" workflow in ComfyUI runs through this node, whether you see it or not. Set Latent Noise Mask is the difference between denoising the whole picture and denoising only the bit you told it to. If your inpainting keeps rewriting things outside the mask - or the masked area comes out looking unrelated to the image around it - this is the node you're missing.

Here's the mental model. When the sampler works on a latent, it normally adds noise to and then denoises all of it. A noise mask is a second channel of information riding along inside the LATENT object: a black-and-white image where white says "denoise here" and black says "leave these pixels alone." The sampler consults that mask at every step, so the untouched regions stay locked to their original content while the white region is free to become whatever your prompt says. That's the whole trick of inpainting - and it's why people call SetLatentNoiseMask the mechanism, not the workflow.

Two inputs, one output, nothing to configure:

  • samples - a LATENT, usually the VAE encode of your source image.
  • mask - a MASK, typically from LoadImage (as Mask) or a mask node. White = regenerate, black = preserve.
  • Output is the same LATENT with a noise_mask entry attached, ready to feed a KSampler.

Where it fits

The two-node pattern is: VAE Encode the image → Set Latent Noise Mask with your mask → KSampler at a denoise under 1.0 → VAE Decode → composite the result back over the original with ImageCompositeMasked. Why the composite step? Because even with a perfect mask, the VAE encode/decode round trip nudges the unmasked pixels a little (see the lossy-VAE trap in the KB), and pasting only the regenerated region back keeps the rest pixel-identical.

There's a sibling node, VAE Encode (for Inpainting), that does encode + mask-attach + mask-grow in one step. If you're on a standard SD/SDXL stack, that node is usually the cleaner start. Set Latent Noise Mask is the one you reach for when you already have a latent from somewhere else - say you're inpainting an intermediate img2img result mid-chain, or a custom node hands you a latent without a mask and you want to attach one.

Where people get burned

  • Mask resolution. The node reshapes your mask to latent resolution internally (it reshapes to (1, 1, H, W)), but it expects a mask that matches your image dimensions. Feed it a mask from a differently-sized image and the inpainting region lands in the wrong place.
  • Denoise strength. Mask only controls where; denoise controls how much. At denoise 1.0 the masked region is pure regeneration, at 0.3 it's a subtle rework. Forgetting to lower it from 1.0 is the "it ignored my image" complaint that fills the subreddit.
  • Mask not connected. This is embarrassingly common: people wire the mask into the sampler's latent input by mistake, or the custom-node workflow they copied uses a noise-mask-free path. If nothing in your graph ever sets noise_mask, the sampler treats the whole latent as one big mask - you're back to plain img2img.

One last note: the mask travels with the latent, so anything downstream that copies the latent (RepeatLatentBatch, LatentComposite, most utilities) carries it along. That's usually what you want. If a node isn't honoring your mask, check whether it drops the field - the source of Set Latent Noise Mask just copies the dict and sets noise_mask, so the leak is almost always downstream, not here.

Categorymodel/latent

Inputs (2)

NameTypeDefaultDescription
samplesLATENT
maskMASK

Outputs (1)

NameTypeDescription
LATENTLATENT