How to sharpen a blurred image using OpenCV

The OpenCV library plays a vital role in this process, providing various functions for sharpening, brightening, and manipulating images. Sometimes it is necessary to enhance an image's sharpness in image processing for various purposes, such as to improve its perceived sharpness and overall quality.

In Python, we can utilize the OpenCV library to blur a sharpened image by utilizing its different functions specifically designed for sharpening images.

Concept behind image sharpening

Image sharpness is determined by two factors:

  • Resolution: Refers to the size of the image in pixels, and a higher number of pixels results in a higher resolution. Images with more pixels result in finer details and smoother edges, leading to a sharper appearance, making resolution a key factor in achieving image sharpness.

  • Acutance: Measures the contrast at the edges of an image. When an edge has a higher contrast, it appears more distinct and defined to the human eye.

These two factors, resolution, and acutance, play a significant role in determining the sharpness of an image.

Sharpening image using OpenCV

You can use the function to enhance image sharpness in Python using OpenCV. We need to prepare a kernel A kernel is a small matrix or filter used in image processing for operations such as blurring, sharpening, and edge detection. to enhance sharpness.

Here are a few steps that you need to follow for sharpening the image:

  1. Define a kernel with specific values that will emphasize the edges and details in the image.

sharpen_filter=np.array([[-1,-1,-1],
[-1,9,-1],
[-1,-1,-1]])

The significance of the sharpening kernel lies in its ability to enhance image sharpness by amplifying the central pixel intensity. At the same time, it reduces the intensity of neighboring pixels, resulting in improved visual clarity and detail.

  1. We need to install the cv2 library by the following command before we proceed to sharpen the image.

pip3 install opencv-python
  1. Once the kernels are ready and the library is installed, we can use cv2.filter2D() the function to sharpen the image easily. This function applies a linear filter to the image, providing the ability to manipulate the image's sharpness or blur according to your specific requirements.

import cv2
import numpy as np
from matplotlib import pyplot as plt
original= cv2.imread('Blurred Image.png', cv2.IMREAD_UNCHANGED)
plt.imshow(cv2.cvtColor(original, cv2.COLOR_BGR2RGB))
plt.axis('off') # Remove axis labels
plt.show()
print("Blur Image")
# create a sharpening kernel
sharpen_filter=np.array([[-1,-1,-1],
[-1,9,-1],
[-1,-1,-1]])
# applying kernels to the input image to get the sharpened image
sharp_image=cv2.filter2D(original,-1,sharpen_filter)
plt.imshow(cv2.cvtColor(sharp_image, cv2.COLOR_BGR2RGB))
plt.axis('off') # Remove axis labels
plt.show()
print("Sharpened Image")
import React from 'react';
require('./style.css');

import ReactDOM from 'react-dom';
import App from './app.js';

ReactDOM.render(
  <App />, 
  document.getElementById('root')
);
  • Line 13: The provided sharpen_filter represents the kernel used for sharpening of the image.

  • Line 18: cv2.filter2D() applies a sharpening filter to an image.

    • original is the input image.

    • -1 indicates the output image should have the same depth as the input.

    • sharpen_filter is the kernel used to enhance edges and details.

    • sharp_image is the resulting sharpened image.

Conclusion

Image sharpening using the OpenCV library offers three key benefits: reducing blurriness and highlighting specific areas. Using sharpening techniques, images become clearer and visually appealing, important details stand out, and text or fine elements become more readable. With the help of cv2 functions, users can easily enhance image quality and make their visuals more impactful.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved