Use filters

The ImageFilter module is used to apply filters to images. There are plenty of filters available in Pillow, some of which are:

• BLUR
• CONTOUR
• DETAIL
• EDGE_ENHANCE
• EMBOSS
• FIND_EDGES
• SMOOTH
• SHARPEN

Here are a couple of examples. Make sure to import the filters using the from PIL import ImageFilter line.

To blur an image:

blurred_image = img.filter(ImageFilter.BLUR)
blurred_image.show()

To find outlines of the objects in the image:

image_edges = img.filter(ImageFilter.FIND_EDGES)
image_edges.show()

We can also convert an image to black and white. To do this, we use the Image.convert() method and pass it the ‘L’ parameter:

black_white_image = img.convert('L')
black_white_image.show()/span>


<

Geek University 2022