Python PIL | RankFilter() 方法
PIL 是Python Imaging Library,它为Python解释器提供了图像编辑功能。
ImageFilter module
包含一组预定义过滤器的定义,可与Image.filter()
方法一起使用。 PIL.ImageFilter.RankFilter()
创建一个排名过滤器。 rank 过滤器对给定大小的窗口中的所有像素进行排序,并返回第 rank 值。
Syntax: PIL.ImageFilter.RankFilter(size, rank)
Parameters:
size: The kernel size, in pixels.
rank: What pixel value to pick. Use 0 for a min filter, size * size / 2 for a median filter, size * size – 1 for a max filter, etc.
Note: value for rank must be integer type.
使用的图像:
# Importing Image and ImageFilter module from PIL package
from PIL import Image, ImageFilter
# creating a image object
im1 = Image.open(r"C:\Users\sadow984\Desktop\download2.JPG")
# applying the rank filter
im2 = im1.filter(ImageFilter.RankFilter(size = 3, rank = 0))
im2.show()
输出:
# Importing Image and ImageFilter module from PIL package
from PIL import Image, ImageFilter
# creating a image object
im1 = Image.open(r"C:\Users\sadow984\Desktop\download2.JPG")
# applying the rank filter
im2 = im1.filter(ImageFilter.RankFilter(size = 3, rank = 3 * 3-1))
im2.show()
输出:
# Importing Image and ImageFilter module from PIL package
from PIL import Image, ImageFilter
# creating a image object
im1 = Image.open(r"C:\Users\sadow984\Desktop\download2.JPG")
# applying the rank filter
im2 = im1.filter(ImageFilter.RankFilter(size = 3, rank = (3 * 3)//2))
im2.show()
输出: