Nodes/OmniNodes/Latent Anomaly Mask 🚩
ComfyUI Node

Latent Anomaly Mask 🚩

The Latent X-Ray That Flags Weird Spots Before You Decode

By TensorVizionΒ·Created 3 months agoΒ·Updated about 8 hours agoΒ· 0
Latent Anomaly Mask 🚩
  • latent
  • mask
  • corrected_latent
  • report
β—„window_size5β–Ί
β—„std_threshold3.0β–Ί
β—„auto_correctfalseβ–Ί
β—„correct_strength0.50β–Ί

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_correct on, the flagged positions get softened toward the local mean by correct_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_threshold is 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. mask is diagnostic; corrected_latent is 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.

CategoryTensorVizion/Latent

Inputs (5)

NameTypeDefaultDescription
latentLATENTβ€”
window_sizeINT53–31β€”
std_thresholdFLOAT3.00.5–10β€”
auto_correctBOOLEANfalseβ€”
correct_strengthFLOAT0.500–1β€”

Outputs (3)

NameTypeDescription
maskMASKβ€”
corrected_latentLATENTβ€”
reportSTRINGβ€”