ComfyUI Node

Defocus Analysis

Why is that render soft? This node reads the frequency domain

By ThatGlennD·Created about a year ago·Updated about a month ago· 23
Defocus Analysis
  • image
  • defocus_score
  • interpretation
  • fft_heatmap
  • high_freq_mask
methodFFT Ratio (Sum)
normalizetrue
edge_detectorSobel

Most sharpness checkers just convolve the image and report a variance. Defocus Analysis is the one that goes further: it takes the Fourier transform and actually looks at where the high-frequency energy sits, which is the honest way to tell "soft but structured" from "genuinely defocused." It's the most technical node in ThatGlennD's ComfyUI-Image-Analysis-Tools pack, and it earns the complexity.

The mental model: a sharp image has lots of fine detail, which shows up in the Fourier domain as energy spread across the outer rings of the spectrum. A blurred image has that energy crushed toward the center - the fine detail is simply gone. This node measures that ratio and scores it, on a 0–1 scale where 0 is razor sharp and 1 is severe defocus.

The methods

The method combo picks your detector, and they answer different questions:

  • FFT Ratio (Sum) (the default): the share of total spectral energy sitting outside a high-frequency radius. Catches loss of fine detail globally.
  • FFT Ratio (Mean): the same idea, averaged per-pixel instead of summed. It's more sensitive to soft, even blur spread across the whole frame.
  • Hybrid (Mean+Sum): a 50/50 average of the two. The author's README recommends this as the default for general model-quality checking, even though the node ships set to FFT Ratio (Sum). For a first pass on unknown images, switch it to Hybrid.
  • Edge Width: abandons the FFT entirely and measures how fat the edges are - a gradient-based look at how far a detected edge spreads. That's the one to reach for with motion blur or contour softness. It's the only method that uses the optional edge_detector combo (Sobel or Canny, default Sobel).

normalize (default on) clamps the score into that 0–1 range; turn it off if you want the raw ratios for your own math.

Outputs

defocus_score (0 = sharp, 1 = degraded), plus interpretation - a sentence from "Very sharp - no defocus" through "Severe defocus - image degraded," with the score attached. Then two visualizations, both returned as IMAGE tensors:

  • fft_heatmap: the full FFT magnitude spectrum in the Inferno colormap. Sharp images show bright, detailed outer rings; blurred ones collapse to a dim central blob. Once you've seen both side by side you'll never need to squint at an image again.
  • high_freq_mask: the high-frequency regions that actually fed the score, rendered in Turbo. The radius adapts to image resolution, so it works consistently across small and large images.

That second map is the part nobody else gives you - it shows you which frequencies were used to judge the image, which is the difference between a score you trust and a score you argue with.

Install

Manager (search "Image Analysis") or:

cd ComfyUI/custom_nodes
git clone https://github.com/ThatGlennD/ComfyUI-Image-Analysis-Tools
cd ComfyUI-Image-Analysis-Tools
pip install -r requirements.txt

Restart ComfyUI. Dependencies are numpy, opencv-python, matplotlib, scikit-learn, Pillow and torch - pure CPU math, no models.

Common gotchas

  • Pack won't load: scikit-learn is imported at module load by the Color Harmony Analyzer; if it's missing, no node in the pack registers. Windows portable: python_embeded\python.exe -m pip install scikit-learn.
  • comfy_api import error: the pack needs ComfyUI's newer node API - update ComfyUI.
  • First frame only: batches analyze frame 0; feed video frames individually.
  • Reading the score backwards: unlike most of the pack, here low is good. If you're wiring this into a filter, remember 0 = sharp.

Where it fits: paired with Sharpness/Focus Score or Blur Detection, it's the tie-breaker. The simpler nodes tell you that an image is soft; Defocus tells you whether the softness is missing detail (frequency collapse) or smeared structure (edge spread), which points you at different fixes.

CategoryImage Analysis

Inputs (4)

NameTypeDefaultDescription
imageIMAGE
methodCOMBOFFT Ratio (Sum)4 options: FFT Ratio (Sum), FFT Ratio (Mean), Hybrid (Mean+Sum), Edge Width
normalizeBOOLEANtrue
edge_detectoroptCOMBOSobel2 options: Sobel, Canny

Outputs (4)

NameTypeDescription
defocus_scoreFLOAT
interpretationSTRING
fft_heatmapIMAGE
high_freq_maskIMAGE