Aller au contenu

Rank Filter Node

By Kriss Norde

Rank Filter is a statistical filter: for each pixel, it looks at a neighborhood, sorts the values in ascending order, then picks the one at a given position (rank). With rank = middle you get a median filter (excellent for salt-and-pepper denoising); with rank = min or max, a morphological operator similar to Erode/Dilate.

Overview

Rank Filter is used less than Blur or Erode Dilate, but it is a surgical tool for specific cases:

  • Rank = median: removes impulse noise (dust, scratches, hot pixels) without blurring the edges.
  • Rank = min / max: a morphological equivalent (like Erode Dilate but with other kernel shapes).
  • Intermediate rank: custom filters for visual stylization.

Where to find this node

  • Effects Library: Tools > Filter > Rank Filter
  • Quick add: right-click in the Node Editor → Add Tool > Filter > Rank Filter

Ranks explained

For a neighborhood of N pixels, the node sorts these values in ascending order and takes the Nth one. Here are the notable cases:

Rank 1 = Min
Takes the darkest value. The equivalent of an erode = shrinks the bright areas.
Middle rank = Median
The classic median filter. Removes extreme values (abnormal pixels) without blurring. Excellent against salt-and-pepper noise.
Max rank = Max
Takes the brightest value. The equivalent of a dilate = grows the bright areas.
Intermediate ranks
Between min and median: pulls toward the dark areas (a stylized "dark drift"). Between median and max: pulls toward the bright areas. Useful for subtle stylization.

Inputs

  • Input (yellow) - image to filter.
  • Effect Mask (blue) - optional. Limits where it is applied.

Setup

Median case (denoise):
MediaIn (noisy shot) → Rank Filter (rank = median) → MediaOut

Advanced morphology case:
Matte → Rank Filter (rank = min, Size 5) → equivalent of a hard erode

Controls tab

Rank
Position of the pixel in the sorted neighborhood. A low value gives darker pixels (min-like), a value in the middle gives a median filter, a high value gives brighter pixels (max-like).
Size
Size of the neighborhood in pixels. Bigger = stronger effect but slower. Start at 3 (a small 3×3 neighborhood). (default: 3)
Shape
Shape of the neighborhood taken into account. Square (square neighborhood) or Circle (disc). Circle gives a more isotropic result, Square is faster.
Red / Green / Blue / Alpha
Channels the filter applies to.

Use cases

  • Salt-and-pepper denoising - Rank = median, Size 3 or 5: the median filter removes abnormal pixels (dust, hot pixels) while preserving sharp edges. More effective than a Blur for this kind of noise.
  • Scratches on scanned film - median with Size 5-7 along the direction of the scratch = fine scratches disappear without blurring the image.
  • "Quantum" / abstract effect - an extreme rank (min or max) with a large Size = a graphic distortion with areas that eat in or spill over.
  • Cleaning up noisy mattes - median on a noisy matte = a clean matte without blurring the edges (unlike a Blur).
  • Cartoon stylization - median with Size 7-9 → Posterize = flat colors with preserved edges, a cel-shading look.
  • Pre-pass before tracking - a median filter before a tracker = less noise making the lock drift.

Tips

  • Rank = Size² / 2 (approximately) to get a median. In practice, set the rank to the middle of the available range.
  • Median vs Blur vs Bilateral: median is edge-preserving like Bilateral, but better for impulse noise. Bilateral is better for Gaussian noise. Blur is universal but crushes the edges.
  • Size 3 is often enough. Size > 7 = slow render and loss of detail.
  • Circle Shape for a clean result - Square introduces visible square artifacts when Size is large. Circle costs a bit more but looks better.
  • For color denoising, enable all 3 RGB channels. To denoise an alpha (matte), check only Alpha.
  • Not a replacement for Temporal NR - for classic sensor noise (high ISO), prefer temporal denoising (several frames). Rank Filter is spatial (frame by frame), so it is less powerful on Gaussian-type noise.