Box Blur using Python PIL library
In this tutorial, we will be seeing the implementation of BoxBlur() using the Python Imaging Library(PIL). The development of this Library was stopped in 2011. However many programmers still use it today for doing simple image manipulations like Rotating, Blurring, Sharpening etc. As the name suggests by using the BoxBlur() function you can blur the original images as per requirement.
BoxBlur() function using PIL
The box blur filter is a part of the ImageFilter
module. The ImageFilter module contains a set of established filters designed by the developers for our usage.
from PIL import Image as I, ImageFilter as IF cat1= I.open('cat.jpg') cat1.show()
Output
The BoxBlur()
function requires radius parameter to take effect. This function sets each pixel to the average value of pixels in a square box extending radius pixels in each direction.
cat2=cat1.filter(IF.BoxBlur(10)) cat2.show()
Output
You must be wondering why we actually blur a clean and sharp image. Turns out it is actually an essential step for color transition from one edge to another to be smooth.
Also read: Compress JPEG image in Python using PIL
Leave a Reply