Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!
Sharpening Images
Sharpening enhances edges and fine details in an image. It is the opposite of blurring — it amplifies differences between neighbouring pixels.
6 min•By Priygop Team•Updated 2026
Sharpening with Kernels
Sharpening with Kernels
import cv2
import numpy as np
image = cv2.imread("photo.jpg")
# METHOD 1: Kernel-based sharpening
# A sharpening kernel amplifies the centre pixel relative to neighbours
sharpen_kernel = np.array([
[ 0, -1, 0],
[-1, 5, -1],
[ 0, -1, 0]
])
sharpened = cv2.filter2D(image, ddepth=-1, kernel=sharpen_kernel)
# METHOD 2: Unsharp masking (more controllable)
# Subtract a blurred version from the original to get the edges,
# then add them back amplified
def unsharp_mask(image, blur_ksize=(5, 5), strength=1.5):
"""Apply unsharp masking to sharpen an image."""
blurred = cv2.GaussianBlur(image, blur_ksize, 0)
sharpened = cv2.addWeighted(image, 1 + strength, blurred, -strength, 0)
return sharpened
sharpened_um = unsharp_mask(image, strength=1.0)
cv2.imwrite("sharpened.jpg", sharpened)
cv2.imwrite("unsharp_mask.jpg", sharpened_um)
print("Sharpening complete")Diagram
Loading diagram…
Machine Learning follows a structured pipeline from data to deployment