Latent Zero Mask
The 0.5-gray trick for clean full-denoise inpainting
- latent
- mask
- latent
Latent Zero Mask is a small, sharp tool for one specific job: zeroing out the masked region of a latent so that area starts from a clean slate instead of the old image's information. Two inputs - latent and mask - and one output, latent.
Why zero it? Inpainting runs on a spectrum. At low denoise, the sampler refines the existing pixels in the masked region. At denoise 1.0, the region is generated from scratch, which is what you want when you're replacing something entirely - a whole new subject, a new background area. But if you feed the masked region's old content into a full-denoise pass, the model starts from pixels that are about to be thrown away anyway, which costs sampling time and can bias the result. Zeroing the region first is the clean start: the sampler has nothing to preserve there and just generates.
This node is also the explicit companion to Mask-Crop Inpaint | Pre's latent_mask output - that output exists precisely so you can do this kind of latent-side masking, and Latent Zero Mask is the natural consumer.
What it does, precisely
The mask you feed must already be at latent resolution - i.e. 1/8 of the pixel resolution for the standard VAE models (the VAE downsamples in 2× stages, so latent sizes come in multiples of 8). The node multiplies the latent's samples by (1 - mask) in the masked area, zeroing those channels, and returns a new latent dict. It preserves the rest of the latent metadata - it copies the dict and only swaps the samples tensor - so you can feed the output straight into a KSampler.
It validates that the mask batch size matches the latent batch and that the spatial resolutions agree, and it errors if they don't. That "mask must be 1/8 size" mismatch is by far the most common way people hit that error: they feed a full-resolution mask into a latent node. Resample it first (Resample Mask with a scaler that matches the latent's 1/8 dimensions) or use Pre's ready-made latent_mask.
The color-shift connection
The "zero" here is the zero in a specific tradition: masked inpainting on non-zero-terminal-SNR models (the SDXL family) wants the masked latent region prepped so the sampler isn't carrying stale image content. The pack's Mask-Crop Inpaint | Pre handles the equivalent prep on the pixel side by shifting the crop's channel means toward 0.5 - that gray fill - which is the visible-space counterpart of what this node does in latent space. They're two halves of the same idea: give the masked area nothing to work with, so the model creates it fresh.
Installing
Part of comfyui-some-image-processing-stuff:
cd ComfyUI/custom_nodes
git clone https://github.com/wmpmiles/comfyui-some-image-processing-stuff
Restart ComfyUI, or ComfyUI Manager → search "Some Image Processing Stuff". No models, no dependencies beyond PyTorch. It's a niche node - you only need it in full-denoise inpaint workflows - but when that's the workflow, it's the exact right tool.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| latent | LATENT | — | |
| mask | MASK | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| latent | LATENT | — |