ComfyUI Node

Clamp Outliers

Sigma-clip your latents before they turn into fireflies

By spacepxl·Created 3 years ago·Updated 8 months ago· 293
Clamp Outliers
  • latents
  • LATENT
std_dev3.0

"Fireflies" is a term borrowed from path-traced rendering - those single bright pixels that flare up out of nowhere in an otherwise clean render, caused by rare noisy samples spiking way outside the normal range. Latents can get the same problem: occasional per-channel values that spike far outside the normal distribution, and when the VAE decodes them, they show up as bright or dark speckle artifacts that have nothing to do with your actual generation. Clamp Outliers catches those before decode.

How it works

It's a statistical clamp, the same idea as sigma-clipping in data analysis: compute the mean and standard deviation of your latent, then clamp any value that's more than std_dev standard deviations away from the mean back down to that boundary. Anything within the normal range passes through untouched; only the genuine statistical outliers - the values a normal distribution says shouldn't really be there - get pulled in.

Inputs and outputs that matter

Just one real setting:

  • latents - what you're clamping.
  • std_dev (0.1-100, default 3, step 0.1) - how many standard deviations out counts as an outlier. 3 is the classic statistics default (roughly 99.7% of a normal distribution falls within 3 standard deviations, so this clamps only genuinely rare values). Lower it if you're still seeing artifacts after the default pass; raise it if you find it's clamping legitimate high-contrast detail that isn't actually a firefly.

Output: a single LATENT.

Installing it

ComfyUI Manager: search ComfyUI Image Filters. Manual:

cd ComfyUI/custom_nodes
git clone https://github.com/spacepxl/ComfyUI-Image-Filters

Restart. No models - this is a statistics operation on a tensor, essentially free to run. Watch for the pack's opencv dependency conflicting with other installed node packs on startup; the repo ships import_error_install.bat for exactly that, or fix it by hand by uninstalling other opencv variants and keeping only opencv-contrib-python.

Where people get burned

The main judgment call is where to set std_dev. Too aggressive (a low value) and you'll clamp real detail - genuinely high-contrast areas of your image can have legitimately extreme latent values that aren't artifacts at all, and over-clamping shows up as flattened, muddy detail in exactly those regions. Too conservative (a high value) and the firefly you were trying to fix survives the clamp untouched. The default of 3 is a reasonable starting point precisely because it's the standard "genuinely rare" statistical threshold, but if you're chasing a specific artifact, it's worth nudging it down a step at a time rather than jumping straight to an aggressive clamp.

Also worth knowing: this fixes a specific failure mode - sparse, extreme-value spikes - not general noise or grain across the whole image. If your issue is overall noisiness rather than a handful of speckled pixels, this node won't help; that's a sampler or scheduler problem, not an outlier problem.

CategoryImage-Filters/latent

Inputs (2)

NameTypeDefaultDescription
latentsLATENT
std_devFLOAT3.00.1–100

Outputs (1)

NameTypeDescription
LATENTLATENT