Nodes/comfyui-noise-match/Detect Noise Sample Region
ComfyUI Node

Detect Noise Sample Region

Where do you even steal grain from? Let it find the smoothest patch

By fuselayer·Created 10 months ago·Updated 10 months ago· 0
Detect Noise Sample Region
  • image
  • mask
  • noise_sample
  • info
detection_methodautomatic
sample_size256
smoothness_threshold0.0050

To match a real photo's noise you first need some of that noise to sample - and you can't just grab any random crop of a photo. A patch of a face or a patterned shirt is full of image content, not grain. What you want is the opposite: the flattest, most boring patch you can find, where the pixels are basically nothing but sensor noise. A patch of sky. A clean wall. An out-of-focus background.

NoiseRegionDetector is the node that finds that patch for you. It's the first step in the fuselayer noise-match pipeline: this crops the sample, RealNoiseExtractor turns it into a reusable pattern, ApplyNoisePattern stamps it back. This node just solves "where."

How it works

It looks for the lowest-variance square region of the image. With OpenCV installed it runs a local-variance + connected-components pass to find the biggest smooth area (the "advanced" method); without OpenCV it falls back to a plain grid search over candidate windows. Either way, the output is always exactly sample_size × sample_size pixels - even if that means clamping down on a small image.

Three inputs actually matter:

  • detection_method - automatic (find the smooth region), mask_based (respect your mask), or center_crop (just take the middle, which is fine for a test).
  • sample_size - the extracted square's edge in pixels. 256 is the default and a fine starting point; you don't need huge for a tileable grain pattern.
  • smoothness_threshold - how strict the "smooth" bar is. Lower = smoother-only, higher = more permissive. Drop it if the detector keeps landing on textured spots.

There's a mask input too, and here's the nice part: mask wins. The code is explicitly mask-first - if you connect a non-empty mask, it's used regardless of detection_method. It scans inside the masked area for the smoothest full-size window, and if nothing fits it centers the crop on the mask's bounding box. So when automatic detection picks a weird spot, you don't fight it - just mask the area you actually want.

Outputs

  • noise_sample - the square IMAGE crop, ready for RealNoiseExtractor.
  • info - a STRING with the region coordinates, variance, mask coverage %, and a quality verdict (Excellent / Good / Fair / Poor). If it prints WARNING: High variance, the extracted area is too textured to read as noise - tighten the threshold or use a mask.

The one thing beginners get wrong

Sample from the image you're compositing onto, not some other photo. Grain is per-image: sensor, ISO, lens, lighting all change it. A patch of your background's own sky or wall is ideal, because the grain you're matching lives in that same capture. Grabbing "some nice grain" from an unrelated photo is why composites still look off after all this work - the noise signature doesn't match the thing you're trying to blend into. This is the same lesson the community keeps relearning about photorealism: the finish has to come from the same world as the scene.

Install and troubleshooting

It ships in fuselayer/comfyui-noise-match along with the rest of the pack. ComfyUI Manager (search "comfyui-noise-match") or:

cd ComfyUI/custom_nodes
git clone https://github.com/fuselayer/comfyui-noise-match

Restart, find it under image/noise. No model downloads. The only real dependency to worry about is OpenCV - the advanced detector uses it, but the node works without it via the scipy fallback, so a missing install degrades, not crashes.

If automatic keeps choosing a bad area, your best move isn't threshold-tuning forever - it's mask_based with a hand-drawn mask on the flattest patch you can see. That's the workflow the author clearly built for, and it's the one that stops wasting your time.

Categoryimage/noise

Inputs (5)

NameTypeDefaultDescription
imageIMAGE
detection_methodCOMBOautomaticautomatic: Find smooth regions | mask_based: Use provided mask | center_crop: Simple center
sample_sizeINT25664–1024Size of extracted square region (pixels)
smoothness_thresholdFLOAT0.00500.0001–0.1Lower = stricter (smoother areas only). Higher = more permissive
maskoptMASK

Outputs (2)

NameTypeDescription
noise_sampleIMAGE
infoSTRING