Nodes/Allor Plugin/ImageFilterRank
ComfyUI Node

ImageFilterRank

One dial to slide between min, max, and everything between

By Nourepide·Created 3 years ago·Updated 2 years ago· 295
ImageFilterRank
  • images
  • IMAGE
size2
rank1

Here's the trick the Allor filter family hides in plain sight: Min, Max, and the "median-ish" cleanup you actually want are all the same operation with a different rank. ImageFilterRank is that generalization. Every pixel in the output is the nth darkest value in its neighborhood, and by changing one number you sweep from morphological erosion (rank 1) through a middle ground that behaves like a median filter to maximum at the top end. If you've ever wished a Min filter came with a softer setting, this is it.

It's part of the Allor Plugin (Nourepide/ComfyUI-Allor), the pack that runs filters in tensor-to-PIL space and preserves alpha and batches. Rank is the flexible middle sibling of Min and Max - you'll mostly reach for it when neither extreme feels right, or when you want one node that can behave as both depending on how you set it.

How it works

Rank wraps PIL's ImageFilter.RankFilter(int(size) + 1, rank). The neighborhood is size + 1 on a side (so size 2 → a 3×3 kernel, and it steps by 2 to stay odd). Inside that window the pixels are sorted, and rank picks which position wins:

  • rank = 1 - the darkest pixel wins. That's exactly ImageFilterMin: kills bright specks, erodes highlights, darkens.
  • rank = kernel area / 2 (roughly) - the middle of the sorted list, so this behaves like a median filter: removes outliers of both polarities, smooths speckle without much edge damage. For a 3×3 kernel that's rank 4 or 5.
  • rank = kernel area - the brightest wins. That's ImageFilterMax: removes dark specks, inflates highlights.

Because rank is an integer with no forced step, you can land anywhere between those extremes, which is what no other node in the family offers. A rank of 2 or 3 in a 3×3 window, for example, gives you most of the bright-speck removal with noticeably less darkening than true Min. That's the sweet spot most people are actually after.

Inputs and outputs

  • images (IMAGE) - single frame or batch; all are processed.
  • size (INT, default 2, step 2) - neighborhood width. Bigger window = stronger effect, more detail loss.
  • rank (INT, default 1) - which sorted position wins. The whole point of the node; slide it.

Output is an IMAGE at the same resolution and channel count, alpha intact, ready to chain into further Allor nodes or straight to a preview/save.

Installing it

Same pack, same path: ComfyUI Manager → search "Allor Plugin" → install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/Nourepide/ComfyUI-Allor

Then restart. It's pure PIL, no models to download. Note the pack creates a config.json on first launch with daily auto-update on; you can edit it to change update frequency or disable modules you never use.

Where people get burned

Don't set rank without thinking about the kernel size. The valid range is 1 to (size+1)², so a rank that's "middle" on a 3×3 kernel is near-min on a 7×7 one. If your goal is median-style cleanup, set size first and then pick the middle rank for that window. And remember rank filters are detail-eaters at the extremes - if the image looks eroded or bloated, you've leaned too hard toward 1 or max, and the answer is to pull rank toward the middle, not to shrink the image.

Categoryimage/filter

Inputs (3)

NameTypeDefaultDescription
imagesIMAGE
sizeINT2
rankINT1

Outputs (1)

NameTypeDescription
IMAGEIMAGE