Overview:
- A sharpening filter makes the transition between the various regions present in an image more obvious rather than being smooth.
- As an image passes through a sharpening filter the brighter pixels are boosted as relative to its neighbors.
Sharpening an image using Python Image processing Library – Pillow:
- The class ImageFilter.SHARPEN of the Pillow library implements a spatial filter using convolution to sharpen a given image.
- An image object is constructed by passing a file name of the Image to the open() method of the Pillow’s Image class.
- To get a filter applied onto an image the filter() method is called on the Image object. Only the class name of the filter is passed as the parameter.
- In the Python example below, the name of the filter class passed is ImageFilter.SHARPEN, an object of which is created within. ImageFilter.SHARPEN has the convolution matrix for sharpening.
- The convolution matrix used is,
(-2, -2, -2,
-2, 32, -2,
-2, -2, -2)
a 3x3 matrix.
- The filter() method applies the convolution matrix to the image pixels and returns the sharpened image.
Example:
from PIL import Image # Open an already existing image # Apply sharp filter # Show the sharpened images |
Output:
Original Image:
Image after applying the Pillow's ImageFilter.SHARPEN filter once:
Image after applying the Pillow's ImageFilter.SHARPEN filter twice: