The Python Imaging Library, known as PIL
or pillow
is a Python image-processing library. This library has powerful image processing capabilities, supports many file types, and is built for an effective internal representation of picture data.
There are many modules in the PIL
library for different purposes. One such module is the ImageFilter
module. As the name suggests, the ImageFilter
module in PIL
contains a pre-defined set of filters used for different purposes.
MedianFilter
functionThe median filter is used to pick the median value in a window of a given size. The MedianFilter()
function creates a median filter.
Median is the middle term in a sorted array.
PIL.ImageFilter.MedianFilter(size=3)
size
: This is the window size.from PIL import Image, ImageFilterimg = Image.open("/test.png").convert('RGB')filter_size = 3median_filter_img = img.filter(ImageFilter.MedianFilter(size=filter_size))median_filter_img.save("output/median_filter_image.png")
Image
and ImageFilter
modules from PIL
.filter()
function on the image object. The median filter is passed as an argument to the filter()
function.ModeFilter
functionThe mode filter is used to pick the most occurring pixel value in a window of a given size. The ModeFilter
function creates a mode filter. If no pixel value occurs more than twice, the original pixel value is preserved.
PIL.ImageFilter.ModeFilter(size=3)
size
: This is the window size.from PIL import Image, ImageFilterimg = Image.open("/test.png").convert('RGB')filter_size = 3mode_filter_img = img.filter(ImageFilter.ModeFilter(size=filter_size))mode_filter_img.save("output/mode_filter_image.png")
Image
and ImageFilter
modules from PIL
.filter()
function on the image object. The mode filter is passed as an argument to the filter()
function.Free Resources