Contents
Python Pillow – Sharpen Image
You can change the sharpness of the image using ImageEnhance class of PIL library.
In this tutorial, we shall learn how to sharpen an image, or blur an image using ImageEnhance class of Python Pillow(PIL) library, with the help of some well illustrated examples.
Steps to Sharpen Image using PIL
To adjust image sharpness using Python Pillow,
- Read the image using Image.open().
- Create ImageEnhance.Sharpness() enhancer for the image.
- Enhance the image sharpness using enhance() method, by the required factor.
By adjusting the factor you can sharpen or blur the image.
While a factor of 1 gives original image. factor>1 sharpens the image while factor<1 blurs the image.
Example 1: PIL – Adjust Image Sharpness
In the following example, we will sharpen the image with a factor of 1, which gives our original image. Then with a factor of 2, which gives a sharpened image. And then with a factor of 0.05, which gives a blurred image.
Python Program
from PIL import Image, ImageEnhance
im = Image.open("original-image.png")
enhancer = ImageEnhance.Sharpness(im)
factor = 1
im_s_1 = enhancer.enhance(factor)
im_s_1.save('original-image-1.png');
factor = 0.05
im_s_1 = enhancer.enhance(factor)
im_s_1.save('blurred-image.png');
factor = 2
im_s_1 = enhancer.enhance(factor)
im_s_1.save('sharpened-image.png');
Original Image – original-image.png

Sharpened Image – sharpened-image.png

Blurred Image – blurred-image.png

Summary
In this tutorial of Python Examples, we learned how to adjust the sharpness of the image using ImageEnhance.Sharpness() function.