task3
task3
Introduction
This report explains the process of sharpening an image using Python. The image is loaded, converted
to the RGB format for display compatibility with Matplotlib, and processed using a sharpening kernel to
enhance its details. The implementation employs OpenCV, NumPy, and Matplotlib for image manipulation,
computations, and visualization.
The input image is located at C:\Users\Shrikanth\OneDrive\Desktop\task3.jpg. The output, including
the original and sharpened images, is displayed for comparison. Additionally, the sharpened image is saved to
a specified directory for further use.
Objectives
1. Load the image file using OpenCV.
2. Apply a sharpening filter using a predefined kernel.
3. Display the original and sharpened images using Matplotlib.
4. Save the processed sharpened image to the desired location.
Methodology
1. Image Loading
o The image is loaded using OpenCV’s cv2.imread() function with the specified path.
o Error handling ensures the program provides an appropriate message if the image cannot be
loaded.
2. Sharpening Filter
o A predefined sharpening kernel is created using NumPy.
o OpenCV’s cv2.filter2D() function applies the kernel to the image, enhancing its details.
3. Image Conversion for Visualization
o The image is converted from BGR (OpenCV format) to RGB for compatibility with
Matplotlib.
o Both the original and processed images are prepared for visualization.
4. Visualization
o The original and sharpened images are displayed side-by-side using Matplotlib for comparison.
5. Image Saving
o The processed sharpened image is saved to the specified path using OpenCV’s cv2.imwrite()
function.
Program
import cv2
import numpy as np
import matplotlib.pyplot as plt
1
# Image path
image_path = r"C:\Users\Shrikanth\OneDrive\Desktop\task3.jpg"
plt.show()
Results
1. Output Path:
The sharpened image is saved successfully to:
C:\Users\Shrikanth\OneDrive\Desktop\sharpened_task3.jpg.
2
2. Original Image:
3. Sharpened Image:
Applications
1. Image Enhancement:
o Improves details and edges in images for better clarity.
2. Preprocessing for Computer Vision:
o Enhances features that are crucial for machine learning models.
3. Medical Imaging:
o Enhances critical features in X-rays, MRIs, and other scans.
4. Photography:
o Improves the sharpness of images for professional editing and publishing.
Conclusion
The described process effectively demonstrates the use of Python and its libraries to sharpen an image
and visualize the results. The sharpening kernel enhances details, making it a valuable tool in applications
requiring image preprocessing. By leveraging OpenCV, NumPy, and Matplotlib, the workflow is efficient,
modular, and adaptable for various image processing tasks.