Python PIL – Enhance edges more in Image

In this post we will be creating a Python script that will apply an effect that will enhance the edges within an existing image, to do this we will be using the Python Imaging Library also known as PIL enabling us to image processing capabilities.

See the sample of Python code below where we utilise the PIL library to enhance the edges in an image and then save it. We start by opening the image and then using the ‘ImageFilter’ module we are able to apply our desired effect. This project uses the ‘Image.enhance_more()’ method which is similar to the ‘Image.enhance()’ with an even stronger edge enhancement filter being applied to the image.

from PIL import Image, ImageFilter

img=Image.open('image.png')

img_edge = img.filter(ImageFilter.EDGE_ENHANCE_MORE)

img_edge.save('enhancedEdgesMore_image.png')

See an example image below before the effect.

Python PIL - Enhance edges more in Image before

See an example image below with the effect.

Python PIL - Enhance edges more in Image after

Take a look at some of our other content around the Python programming language by clicking here.

Leave a Reply