As to perform the task by reading and learning its resources the task gives certain leanings that are :
Image enhancement techniques in OpenCV help improve image quality by adjusting brightness, contrast, smoothing, sharpening, and detecting edges. These methods allow better visuals and feature extraction from images.
The outcomes include:
• Contrast and Brightness: Adjusting the visual appeal of an image.
• Smoothing and Sharpening: Reducing noise or enhancing details.
• Edge Detection: Identifying boundaries and edges for further analysis.
Use of openCV in Python for Image Enhancement
Code:
import cv2 import numpy as np image = cv2.imread("C:/Users/YourUsername/Pictures/sample.jpg") gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) cv2.imshow("Grayscale Image", gray_image) blurred_image = cv2.GaussianBlur(image, (5, 5), 0) cv2.imshow("Blurred Image", blurred_image) edges = cv2.Canny(image, 100, 200) cv2.imshow("Edge Detection", edges) bright_image = cv2.convertScaleAbs(image, alpha=1.2, beta=50) cv2.imshow("Brightness Increased", bright_image) kernel = np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]]) sharpened_image = cv2.filter2D(image, -1, kernel) cv2.imshow("Sharpened Image", sharpened_image) cv2.waitKey(0) cv2.destroyAllWindows()
Explanation:
The code by me in above task gives steps that loads the image first and then showing it in black and white and blur it and detecting the edges and increase the brightness. make it sharpen and display the final things and stop .
OUTPUT:
Here I am taking example for the steps that are :
- Open an image:
image = cv2.imread("C:/Users/YourUsername/Pictures/sample.jpg")
This loads an image from your computer and sample can be any thing from my pc or storage . - Convert to black and white (grayscale):
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
This changes the image to grayscale, like a black-and-white photo. - Blur the image:
blurred_image = cv2.GaussianBlur(image, (5, 5), 0)
This makes the image look softer by blurring it a little. - Edge detection:
edges = cv2.Canny(image, 100, 200)
This shows the edges (like outlines) in the image, making them easier to see. - Increase brightness:
bright_image = cv2.convertScaleAbs(image, alpha=1.2, beta=50)
This makes the image brighter, like turning up the light. - Sharpen the image:
sharpened_image = cv2.filter2D(image, -1, kernel)
This makes the details in the image stand out more, like using a sharper focus. - Display the images:
Each version (grayscale, blurred, edges, etc.) is shown in separate windows so you can see the changes.
The resources that are used by me are :
https://www.geeksforgeeks.org/image-enhancement-techniques-using-opencv-python/
https://www.tome01.com/enhance-restore-images-with-opencv-and-python/
The image enhancement is clear by these things to me to good extent thank you .