Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python

What is BoxBlur in Python?

Ravi

The PIL library

Pillow, PIL, or the Python Imaging Library is an image processing library in Python. This library supports a wide range of file formats, is designed for an efficient internal representation of image data, and provides powerful image processing capabilities.

The ImageFilter module

The ImageFilter module in PIL contains definitions for a pre-defined set of filters that are used for different purposes.

The BoxBlur function

The BoxBlur filter function sets each pixel to the average value of the pixels in a square box. It extends the radius pixels in each direction to blur the image.

Syntax

PIL.ImageFilter.BoxBlur(radius=2)

Parameter

  • radius: This is the size of the box in one direction. A zero radius does not blur the image.

Example

from PIL import Image, ImageFilter
import matplotlib.pyplot as plt

img = Image.open("man.png")
     
img_blur = img.filter(ImageFilter.BoxBlur(4))
     
img_blur.save("man_blur.png")

Explanation

  • Line 1: We import the ImageFilter and Image modules.
  • Line 3: man.png is read into memory using open() in the Image module.
  • Line 5: We apply the BoxBlur filter with the radius 4 to the image we load in Line 3.
  • Line 7: We then save the blurred image.

RELATED TAGS

python
RELATED COURSES

View all Courses

Keep Exploring