Latent Anomaly Mask π©
The Latent X-Ray That Flags Weird Spots Before You Decode
- latent
- mask
- corrected_latent
- report
Latents are the compressed representation the diffusion model actually works in - 8x smaller per side than the image, 4 channels for SDXL, 16 for Flux. You can't see them, and that's the problem this node exists for. Latent Anomaly Mask runs a statistical scan over a sampled latent and flags the spatial regions that are statistical outliers - the hot spots, the corrupted blobs, the parts where something went wrong before you've spent a VAE decode finding out. Think of it as an X-ray for your latent, showing you the injuries before you develop the film.
How it works
For every spatial position it computes the local mean and standard deviation in a sliding window of window_size pixels, then compares the local value against that neighborhood. Anything more than std_threshold standard deviations away gets flagged. That's a per-region check, not a global one - a latent can be perfectly healthy overall and still contain a small pathological patch, which is exactly what a global mean/std check would miss.
It returns three things:
- mask - highlights the flagged regions. Wire this into an inpainting workflow after decode, or use it with Image Mask Composite to paint over the bad area.
- corrected_latent - with
auto_correcton, the flagged positions get softened toward the local mean bycorrect_strength. A light touch (0.3β0.5) can smooth a glitchy region without flattening the whole latent. - report - a text summary of how much of the latent got flagged.
Inputs that matter
Only a few are worth touching:
- window_size (3β31, default 5) - how big a neighborhood defines "local". Bigger windows call more things anomalous because the reference region is broader.
- std_threshold (default 3) - how many standard deviations before it's "anomalous." 3 is a reasonable start; raise it if the mask lights up like a Christmas tree on healthy images.
- auto_correct / correct_strength - whether to actually fix, and how hard.
When you'd actually reach for it
This is a debugging and QC node more than a creative one. The best use is in a batch run: throw it after the KSampler, read report, and let a gate decide whether to decode a latent that came out looking like a glitch. It pairs naturally with the pack's Latent QC Gate (the automated pass/fail version of this idea) and Latent Histogram (which shows you the distribution shape). If you're doing unattended batch generation, a node that catches the corrupted samples before the VAE wastes time on them is worth its weight.
Install
Standard OmniNodes story - no extra dependencies, because latent math here is pure NumPy/PyTorch, both bundled with ComfyUI:
cd ComfyUI/custom_nodes
git clone https://github.com/TensorVizion/OmniNodes
Restart, then look under TensorVizion/Latent in the node search. ComfyUI Manager (search "OmniNodes") works too. After cloning, check the terminal for [OmniNodes] β
Loaded lines so you know the file registered.
Troubleshooting
- Everything is flagged. Drop
std_thresholdis the wrong move - raise it. If 3 flags half the latent, either the latent is genuinely broken or you want a 4β5 threshold. - Nothing is flagged but the image looks bad. The anomaly is global, not local - a uniform wash won't trip a local outlier check. That's a job for the QC Gate's near-blank check instead.
- The mask and corrected_latent disagree with each other. They're separate outputs doing separate jobs.
maskis diagnostic;corrected_latentis what you actually feed downstream. Don't feed the mask into a decode expecting it to be an image - it's a mask.
It's a genuinely useful diagnostic in a pack that's mostly about giving you eyes inside latent space. A beginner's honest take: use it when something's visibly wrong and you want to know where, not as a permanent fixture in every workflow.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| latent | LATENT | β | |
| window_size | INT | 53β31 | β |
| std_threshold | FLOAT | 3.00.5β10 | β |
| auto_correct | BOOLEAN | false | β |
| correct_strength | FLOAT | 0.500β1 | β |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| mask | MASK | β |
| corrected_latent | LATENT | β |
| report | STRING | β |