Applying Blur Filter Using Pillow

Overview:

  • The ImageFilter class in the Python Image-processing Library - Pillow, provides several standard image filters.

 

  • Image filters can be applied to an image by calling the filter() method of Image object with required filter type constant as defined in the ImageFilter class.

 

  • A simple blur filter applies a blurring effect on to the image as specified through a specific kernel or a convolution matrix.

 

  • The blur filter is applied by doing a convolution operation between the image and the kernel.

 

  • The convolution matrix used by Pillow in ImageFilter.BLUR is a 5x5 kernel:

        (

        1,  1,  1,  1,  1,

        1,  0,  0,  0,  1,

        1,  0,  0,  0,  1,

        1,  0,  0,  0,  1,

        1,  1,  1,  1,  1

        )

 

  • There are alternates available to a convolution filter like IFFT - Inverse Fast Fourier transform, IIR and FIR.

 

Python Example - ImageFilter.BLUR:

 

# import image module

from PIL import Image

from PIL import ImageFilter

 

# Open an already existing image

imageObject = Image.open("./fish.jpg")

imageObject.show() 

 

# Apply blur filter

blurred = imageObject.filter(ImageFilter.BLUR)

blurred = blurred.filter(ImageFilter.BLUR)

blurred.show()

 

Output- ImageFilter.BLUR:

Before applying the blur filter:

Before applying blur filter - python pillow example

After applying the blur filter:

After applying blur filter - python pillow example


Copyright 2019 © pythontic.com