How do you select the second-brightest neighbor?

RankFilter selects a zero-based position in the ordered neighborhood.

Pixel experiment and interpretation

In a three-by-three window, rank seven selects the runner-up. If two defective sensors are both bright, skipping just the maximum leaves one in play.

from PIL import Image, ImageFilter

im=Image.frombytes('L',(3,3),bytes([1,2,3,4,5,6,7,80,250]))
im.filter(ImageFilter.RankFilter(3,7)).getpixel((1,1))

Result 80

中文

怎样选邻域内第二亮的值并忽略最亮离群点?

RankFilter 的 rank 是排序窗口中从零开始的位置。

像素实验与适用边界

三乘三窗口共有九个数,索引 7 对应第二亮。若两个传感器坏点都很亮,只跳过第一名仍会留下一个。

from PIL import Image, ImageFilter

im=Image.frombytes('L',(3,3),bytes([1,2,3,4,5,6,7,80,250]))
im.filter(ImageFilter.RankFilter(3,7)).getpixel((1,1))

结果 80

References / 参考来源

Keep reading / 继续阅读