PIL or Python Imaging Library is an image processing library in Python. This library supports a wide range of file formats. It is designed for an efficient internal representation of image data and provides powerful image processing capabilities.
ImageFilter ModuleThe ImageFilter module from PIL contains definitions for a predefined set of filters that are used for different purposes.
MinFilter functionThe MinFilter function creates a min filter. This is used to pick the lowest pixel value in a window of a given size.
PIL.ImageFilter.MinFilter(size=3)
size: This represents the window size.MaxFilter functionThe MaxFilter function creates a min filter. This is used to pick the largest pixel value in a window of a given size.
PIL.ImageFilter.MaxFilter(size=3)
size: This represents the window size.from PIL import Image, ImageFilterimport matplotlib.pyplot as pltimg = Image.open("man.png")filter_size = 3min_img = img.filter(ImageFilter.MinFilter(size=filter_size))min_img.save("min_img.png")max_img = img.filter(ImageFilter.MaxFilter(size=filter_size))max_img.save("max_img.png")
ImageFilter and Image modules.open() from the Image module to read man.png into memory.filter_size.MinFilter with size as filter_size
to the image we loaded in line 3.MinFilter to disk.MaxFilter with size as filter_size
to the image we loaded in line 3.MaxFilter to disk.