Sharpening images

In connection with this last function, there are some options you can try in order to sharpen the edges of your images. One simple approach is to perform what is known as unsharp masking, where an unsharp, or smoothed, version of an image is subtracted from the original image. In the following example, a Gaussian smoothing filter has been applied first and the resulting image is subtracted from the original image:

 smoothed = cv2.GaussianBlur(img, (9, 9), 10) unsharped = cv2.addWeighted(img, 1.5, smoothed, -0.5, 0)

Another option is to use a specific kernel for sharpening edges and then apply the cv2.filter2D() function. In the sharpening_techniques.py script, there are some defined kernels that can be applied for this purpose. ...

Get Mastering OpenCV 4 with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.