Python PIL BoxBlur() method

Python PIL BoxBlur() Method

PIL is the Python Imaging Library, which provides image editing capabilities for the Python interpreter. The ImageFilter module contains definitions for a set of predefined filters that can be used with the Image.filter() method.
PIL.ImageFilter.BoxBlur() blurs an image by setting each pixel to the average of the pixels in a square box, which extends by radius pixels in each direction. It supports floating radius values of arbitrary sizes. Using an optimized implementation, the runtime is linear in the image size for any radius value.

Syntax: PIL.ImageFilter.BoxBlur()

Parameters:
radius: The size of the box in one direction. A radius of 0 does no blurring, returning an identical image. A radius of 1 takes 1 pixel in each direction, for a total of 9 pixels.

Images used:

Python PIL BoxBlur() method

# Importing Image and ImageFilter module from PIL package
from PIL import Image, ImageFilter
     
#creating an image object
im1 = Image.open(r"C:Userssadow984Desktopdownload2.JPG")
     
# applying the boxblur method
im2 = im1.filter(ImageFilter.BoxBlur(0))
     
im2.show()

Output:

Python PIL BoxBlur() method

# Importing Image and ImageFilter module from PIL package
from PIL import Image, ImageFilter
     
#creating an image object
im1 = Image.open(r"C:Userssadow984Desktopdownload2.JPG")
     
# applying the boxblur method
im2 = im1.filter(ImageFilter.BoxBlur(2))
     
im2.show()

Output:

Python PIL BoxBlur() method

# Importing Image and ImageFilter module from PIL package
from PIL import Image, ImageFilter
     
#creating an image object
im1 = Image.open(r"C:Userssadow984Desktopdownload2.JPG")
     
# applying the boxblur method
im2 = im1.filter(ImageFilter.BoxBlur(8))
     
im2.show()

Output:

Python PIL BoxBlur() method

Leave a Reply

Your email address will not be published. Required fields are marked *