ComfyUI Node

Image SSIM

The metric that roughly tracks your eyeballs

By NobutakaKuroki·Created about a month ago·Updated about a month ago· 2
Image SSIM
  • image_a
  • image_b
  • ssim

PSNR and MAE compare pixels, and pixels are not what your eyes compare. SSIM is the third member of the comfyui-image-metrics pack and the one that tries to match human perception: it compares local structure - brightness, contrast, texture - inside a sliding window instead of raw pixel deltas. Same two-image setup, same single-number output, but the number tends to line up with what "looks better" means to you, which is why it's the metric you pair with PSNR when one of them is saying something dumb. The score runs up to 1.0 for identical images (in practice it can dip negative for wildly different ones, so treat "closer to 1" as the whole mental model).

How it works

This is the 2004 Wang et al. Structural Similarity Index, implemented faithfully: an 11x11 Gaussian window (sigma 1.5) slides over each channel, and for every neighborhood it estimates local mean, variance, and covariance to score luminance, contrast, and structure, stabilized by the standard constants K1=0.01 and K2=0.03. Each channel is filtered independently via a depthwise convolution, then everything is averaged. The important design choice: no parameters are exposed. You can't tune the window or the constants, and that's deliberate - those defaults are literally what "SSIM" means in the literature, so any number you produce is comparable to any paper or tool that quotes SSIM. It also assumes the standard 0..1 IMAGE range, same as the pack's PSNR.

The lesson the README wants you to learn

The pack's second sample workflow is the same downscale-and-upscale comparison as the PSNR lesson - bilinear, bicubic, lanczos - but scored with SSIM instead. Run both and you'll see them disagree, and that disagreement is the actual teaching point. Pixel-error metrics reward smoothness; SSIM rewards structural fidelity. When bicubic wins on PSNR but lanczos wins on SSIM, you've learned more about your resampler than either metric alone would tell you. That's the honest way to use these tools: they're not competing, they're cross-checking.

Inputs and outputs

Two required IMAGE inputs, image_a and image_b - same shape, as always in this pack.

  • ssim (FLOAT) - the structural similarity score, closer to 1.0 = more similar. Wire it downstream or just read it.

It's an output node like its siblings, so the value prints on the node with nothing connected.

Installing it

ComfyUI Manager, search "comfyui-image-metrics", or:

cd ComfyUI/custom_nodes
git clone https://github.com/NobutakaKuroki/comfyui-image-metrics

Restart ComfyUI, find it under KULab → Metrics. No extra dependencies, no model downloads - this is pure torch math from Dr. Nobutaka Kuroki's teaching pack, so if you want to see exactly what an SSIM implementation looks like, the source is short and heavily commented.

Where people get burned

The batch-averaging gotcha applies here too - one score for the whole batch, no batch_index to isolate a pair. And keep your expectations calibrated: a visually "identical" re-save can still shave points off a perfect 1.0 because resampling and float rounding count as structural change. The bigger trap is treating SSIM as if it is perception. It's a proxy with a well-known blind spot - it can rate a result with a nasty localized artifact surprisingly well, because the artifact is small relative to the window-averaged map. Use it as the eye-adjacent second opinion alongside PSNR/MAE, not as the final judge.

CategoryKULab/Metrics

Inputs (2)

NameTypeDefaultDescription
image_aIMAGE
image_bIMAGE

Outputs (1)

NameTypeDescription
ssimFLOAT