Adjusting Image Sharpness with Python and Pillow
Photographers try to take photos that are in focus, or sharp. When they fail to do so, the images are blurry. You can sometimes make a blurry image look better by using a sharpening technique. You can also sharpen an image that is already in focus to make it look even better. You should try both methods on your photos as one may work better depending on what part of your image needs to be sharpened.
If you apply an enhancement factor of 0.0, your image will be blurry. If you use 1.0, you will get a copy of the original image back. An enhancement factor of 2.0 will result in a sharpened image.
You will be using this photo of a hummingbird from Northern Minnesota:
To see how to use a sharpness enhancement factor, create a new file named enhance_sharpness.py and add this code:
In this example, you use the Sharpness() class to create your enhancer object. Then you use an enhancement factor of 2.5 to apply sharpness to the hummingbird image. The result of your work looks like this:
Once again, when it comes to sharpening an image, it is very subtle. You have to look at both images side by side to really see the difference. You could try using an enhancement factor of 0.0 to make it blurry and then you would likely see what happened. Try this on a few different images of your own and see what happens!
Wrapping Up
You have learned about adjusting images in several other articles in this newsletter this summer. If you missed them, feel free to check the archive. In this article, you focused on making images sharper using Python and the Pillow package.
As you might know, Pillow can do a lot more than simply adjust your images. You can crop, rotate, do image transforms, and much more. You should give Pillow a try and see what you can do!
Want to Learn More?
You can learn more about what you can do with Python and Pillow in Mike’s book, Pillow: Image Processing with Python





