In this post we will be creating a Python script that will smooth an image which will reduce the level of noise and detail present, 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 smooth an Image and then save it to a new file. We start by opening the image and then using the ‘ImageFilter’ module we are able to achieve our desired effect. This project uses the ‘Image.smooth_more()’ method which is similar to the ‘Image.smooth()’ with an even stronger smoothing filter being applied to the image.
from PIL import Image, ImageFilter img=Image.open('image.png') img_smooth=img.filter(ImageFilter.SMOOTH_MORE) img_smooth.save('smooth_more_image.png')
See an example image below before the effect.
See an example image below with the effect.
Take a look at some of our other content around the Python programming language by clicking here.