Image Enhancement Techniques using OpenCV – Python.pptx

mzeon578 295 views 46 slides Jun 01, 2024
Slide 1
Slide 1 of 46
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46

About This Presentation

For knowledge


Slide Content

Image Enhancement Techniques using OpenCV – Python Image enhancement is the process of improving the quality and appearance of an image. It can be used to correct flaws or defects in an image, or to simply make an image more visually appealing. Image enhancement techniques can be applied to a wide range of images, including photographs, scans, and digital images.

Some common goals of image enhancement include increasing contrast, sharpness, and colorfulness; reducing noise and blur; and correcting distortion and other defects. Image enhancement techniques can be applied manually using image editing software, or automatically using algorithms and computer programs such as OpenCV. 

Adjusting brightness and contrast Adjusting the brightness and contrast of an image can significantly affect its visual appeal and effectiveness. It can also help to correct defects or flaws in the image and make it easier to see details. Finding the right balance of brightness and contrast is important for creating an attractive and effective image.

In this example, the brightness of the image is adjusted by adding 10 to each pixel value, and the contrast is adjusted by scaling the pixel values by 2.3. we can adjust the values of brightness and contrast to achieve the desired level of brightness and contrast. .

Another method for adjusting the brightness and contrast of an image is to use the cv2.convertScaleAbs() function, which allows you to adjust the brightness and contrast using a combination of scaling and shifting the pixel values

cv2.convertScaleAbs() function

Sharpening images Sharpening is the process of enhancing the edges and fine details in an image to make it appear sharper and more defined. It is important because it can help to bring out the details and features in an image, making it more visually appealing and easier to understand. Sharpening can be used to correct blur or softness in an image and can be applied using a variety of techniques.

One common method for sharpening images using OpenCV and Python is to use the cv2.filter2D() function, which convolves the image with a kernel. The kernel can be designed to enhance the edges in the image, resulting in a sharper image.

In this example, a 3×3 sharpening kernel is used to enhance the edges in the image. You can experiment with different kernels to achieve the desired level of sharpening. Numpy is used to create the sharpening kernel is created as a NumPy array using the np.array () function. This array is then passed as an argument to the cv2.filter2D() function, which convolves the image with the kernel to sharpen it.

Another method for sharpening images is to use the cv2.Laplacian() function, which calculates the Laplacian of an image and returns the result as a sharpened image.

Removing noise from images Noise reduction is the process of removing or reducing unwanted noise or artifacts from an image. It is important because it can improve the visual quality and clarity of the image and make it easier to analyze or process using computer algorithms. Noise can be introduced into an image due to a variety of factors and can degrade its quality. There are several techniques for reducing noise, including using filters such as the median filter or the Gaussian filter. It is important to apply noise reduction judiciously to avoid blur or loss of detail in the image. One common method for removing noise from images using OpenCV and Python is to use a median filter. The median filter works by replacing each pixel in the image with the median value of a set of neighboring pixels. This can help to smooth out noise and reduce artifacts in the image.

Here is an example of how to remove noise from an image using the cv2.medianBlur() function in OpenCV

In this example, the cv2.medianBlur() function is used to apply a median filter to the image. The 5 parameter specifies the size of the kernel to use for the filter. You can adjust the kernel size to achieve the desired level of noise reduction.

Another method for removing noise from images is to use a Gaussian filter, which uses a weighted average of neighboring pixels to smooth out noise and reduce artifacts. You can use the cv2.GaussianBlur() function to apply a Gaussian filter to an image in OpenCV. Gaussian filter,

Enhancing color in images Color enhancement is adjusting the colors in an image to make them more vibrant, balanced, or natural. It can be used to correct color defects or problems in an image or to simply make an image more appealing and aesthetically pleasing. Color enhancement is important because it can significantly affect the visual impact and effectiveness of an image. It can also be useful for correcting color errors or problems in an image and can make it easier to see details and features in the image. There are several techniques for enhancing the colors in an image, including adjusting the color balance, adjusting the saturation, and adjusting the hue.

There are several ways to enhance the colors in an image using OpenCV and Python. One common method is to use the cv2.cvtColor() function, which allows you to convert the image from one color space to another. This can be useful for adjusting the color balance or saturation of the image.

Image resizing and scaling Image resizing and scaling involve adjusting the dimensions and size of an image. Both are important for meeting specific requirements or context, such as fitting a specific size or aspect ratio or reducing the file size. There are several techniques, including interpolation methods like the nearest neighbor, bilinear, and bicubic interpolation. It is important to choose a method that preserves image quality and clarity. You can use the cv2.resize() function in OpenCV to resize and scale images. The cv2.resize() function takes the following arguments: src : The input image. dsize : The size of the output image, specified as a tuple (width, height). fx : The scaling factor along the x-axis. fy : The scaling factor along the y-axis. interpolation: The interpolation method to use.

Here is an example of how to use the cv2.resize() function to resize an image: Python3

In this example, the image is resized to a width of 400 pixels and a height of 300 pixels. You can also use the fx and fy parameters to specify the scaling factors along the x-axis and y-axis, respectively. For example:

In this example, the image is scaled by a factor of 2 along both axes, resulting in an image that is twice the size of the original. The interpolation parameter allows you to specify the interpolation method to use when resizing or scaling the image. The available options include cv2.INTER_NEAREST, cv2.INTER_LINEAR, cv2.INTER_CUBIC, and others. This is just a basic example of how to resize and scale images using OpenCV and Python. You can adjust the size and scaling factors to achieve the desired results, and you can also specify the interpolation method to use when resizing or scaling the image.

Inverse Transform We can also inverse the color by simply subtracting each value from 255 Python3

Equalizing histograms – Histogram equalization is a technique used to adjust the contrast of an image by spreading out the intensity values of the pixels in the image. It is important because it can improve the contrast and clarity of an image, making it easier to see details and features that might be difficult to see in an image with low contrast. There are several different methods for performing histogram equalization, including global histogram equalization and local histogram equalization. Global histogram equalization adjusts the contrast of the entire image, while local histogram equalization adjusts the contrast in small, localized areas of the image.

You can use the cv2.equalizeHist() function in OpenCV to equalize the histogram of an image. This function takes the image data as an argument and returns the equalized image data. Here is an example of how to use the cv2.equalizeHist() function to equalize the histogram of an image

Other Techniques  Image enhancement is a wide field that involves adjusting images to improve their visual quality or to make them more suitable for further analysis. There are many techniques for enhancing images, such as: Morphological transformations : These are operations based on the image shape. They are typically applied to binary images, but can also be used with grayscale images. Examples include dilation, erosion, opening, closing, etc.  Operations can be used to enhance or modify the shape or structure of objects in an image. To apply morphological operations with OpenCV and Python, you can use functions such as erode, dilate, and morphologyEx . Edge detection : OpenCV provides several functions for performing edge detection, such as Canny(), Sobel(), and Laplacian(). These functions can be used to identify edges in an image by looking for sharp changes in pixel intensity. Color correction : OpenCV provides several functions for adjusting the colors in an image, such as cvtColor () and inRange (). These functions can be used to perform tasks such as color balance, color grading, and white balancing. Image gradients : OpenCV provides several functions for computing image gradients, such as Scharr (), Sobel(), and Laplacian(). These functions can be used to highlight changes in pixel intensity in an image and can be useful for tasks such as edge detection and image segmentation.

Image cropping : Cropping techniques can be used to remove unwanted areas from an image. To crop an image, you can use the copyMakeBorder function to create a new image with the desired dimensions, and then copy the relevant portion of the original image into the new image. Image rotation : Rotation techniques can be used to change the orientation of an image. To rotate an image with OpenCV, you can use the warpAffine function with a rotation matrix. Image blending : Blending techniques can be used to combine two or more images together. To blend images with OpenCV and Python, you can use the addWeighted function to combine the images using a weighted average. Image thresholding : Thresholding techniques can be used to convert an image to black and white by setting a threshold value for pixel intensity. To apply thresholding, you can use the threshold function. Image deblurring : Deblurring techniques can be used to remove blur from an image caused by camera shake, out-of-focus subjects, or other factors. To deblur an image, you can use the wiener function, which applies a Wiener filter to the image.   OpenCV is a powerful library for image processing and computer vision tasks and it provides many advanced image enhancement techniques that can be used for a variety of applications. Some of these techniques are:

Super-resolution : OpenCV provides the pyrUp () and pyrDown () functions for upsampling and downsampling images, respectively. These functions can be used as part of a super-resolution algorithm to increase the resolution of an image. Image restoration : OpenCV provides several functions for image restoration, such as fastNlMeansDenoising () and fastNlMeansDenoisingColored (). These functions can be used to remove noise and improve the visual quality of an image. Image fusion : OpenCV provides the addWeighted () function for combining two images using a weighted sum. This function can be used to fuse multiple images of the same scene to create a single image that contains more information or is of higher quality.

Image segmentation : OpenCV provides several functions for image segmentation, including threshold(), adaptiveThreshold (), and findContours (). These functions can be used to partition an image into regions or segments that correspond to different objects or regions of interest. Image recognition : OpenCV provides several functions for image recognition, including HOGDescriptor () and SIFT(). These functions can be used to extract features from an image and train a machine-learning model to recognize objects or scenes. Object detection : OpenCV provides several functions for object detection, including HOGDescriptor () and SIFT(). These functions can be used to detect and locate objects in an image or video in real time. Image registration : OpenCV provides the registerTranslation () function for aligning or registering two or more images of the same scene. This function can be used to align images from different sensors or from different viewpoints. Image stitching : Image stitching techniques can be used to combine multiple images into a single panoramic or mosaic image. To apply image stitching with OpenCV and Python, you can use techniques such as feature matching, which matches the features in the source images to create a common reference frame, and image warping, which warps the images to align them with the reference frame.
Tags