Make Blurry Images Clear with Python + OpenCV
A complete guide to enhancing image clarity using OpenCV and Python. Learn how to apply convolution kernels to restore edge details in blurry photos.
Step 1: Project Structure & Dependencies
Setup your workspace and install required pip packages
Directory Structure
Create a new folder and set up the following files:
Install Dependencies
We only need OpenCV and NumPy for this task.
opencv-python==4.8.1.78
numpy==1.26.2pip install -r requirements.txtStep 2: Core Algorithm & Code
Using a sharpening kernel with cv2.filter2D
We use a specific 3x3 matrix called a kernel: [[0, -1, 0], [-1, 5, -1], [0, -1, 0]]. The center weight (5) amplifies the target pixel, while the negative surrounding weights (-1) subtract the blurred background. This effectively increases contrast at the edges, making the image appear 'sharper'.
Step 3: Execute & Verification
Run the python script and compare the outputs
Ensure your blurry image is placed in the folder and named correctly, then run the python file.
If the image looks too harsh or noisy, try a softer kernel or apply a slight Gaussian blur before sharpening to reduce noise.
[[-1, -1, -1],
[-1, 9, -1],
[-1, -1, -1]]
)
Explore More#opencv-dev
Cross-Platform OpenCV Compilation and Deep Integration with FFmpeg
ArticleA detailed guide on how to compile OpenCV 4.x cleanly using CMake across multiple platforms, resolve core pkg-config linking issues, and link it into FFmpeg to unlock powerful video vision processing filters.
OpenCV Image Duplicate Detection and Similarity Analysis
ArticleA detailed demonstration of how to use OpenCV for image duplicate detection and similarity analysis, including feature extraction, matching algorithms, and result visualization.
Python Calling OpenCV Image Sharpening
ArticleA detailed demonstration of how to use Python to call OpenCV for image sharpening, enhancing image clarity and detail.
C++ Calling OpenCV Image Sharpening
ArticleA detailed demonstration of how to use C++ to call OpenCV for image sharpening, enhancing image clarity and detail.
C++ OpenCV + FFmpeg 7: Making Videos Clearer from Blurry
ArticleA detailed demonstration of how to use C++ and FFmpeg 7 in conjunction with OpenCV for video processing, achieving clarity from blurriness.
