Image Enhancement Techniques in An Image Processing Pipeline
Image Enhancement Techniques in An Image Processing Pipeline
Contrast Enhancement
Histogram equalisation involves modifying the image's histogram to increase
contrast and broaden the dynamic range of the pixel values.
Adaptive histogram equalisation (AHE) localises contrast enhancement by
segmenting the image into smaller areas to preserve details and prevent over-
amplifying noise.
Contrast Limited Adaptive Histogram Equalisation (CLAHE): Controlling the
contrast enhancement process to prevent noise from being amplified.
Image source- google
Colour Correction
Correcting for colour casts brought on by various lighting situations in order to restore
proper colour representation.
Colour transfer: Aligning the colour appearance by transferring colour attributes from a
reference image to the target image.
Colour Constancy: Ensuring that colours remain consistent across photographs despite
changes in lighting.
Image source- google
The code using the OpenCV library for Color Correction
import cv2
import numpy as np
def correct_colors(image, balance):
# Convert the image from BGR to LAB color space
lab_image = cv2.cvtColor(image, cv2.COLOR_BGR2LAB)
# Split the LAB image into L, A, and B channels
l_channel, a_channel, b_channel = cv2.split(lab_image)
# Apply the balance to the A and B channels
a_channel = cv2.add(a_channel, balance[0])
b_channel = cv2.add(b_channel, balance[1])
# Clip the values to the valid range [0, 255]
a_channel = np.clip(a_channel, 0, 255)
b_channel = np.clip(b_channel, 0, 255)
# Merge the updated L, A, and B channels back into a LAB image
corrected_lab_image = cv2.merge((l_channel, a_channel, b_channel))
# Convert the corrected LAB image back to BGR color space
corrected_image = cv2.cvtColor(corrected_lab_image, cv2.COLOR_LAB2BGR)
return corrected_image
# Load the image
image = cv2.imread('input_image.jpg', cv2.IMREAD_COLOR)
# Adjust the color balance parameters
balance = [-10, 20] # Balance values for A and B channels
# Correct the colors
corrected_image = correct_colors(image, balance)
# Display the original and corrected images
cv2.imshow('Original Image', image)
cv2.imshow('Corrected Image', corrected_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
import cv2
import numpy as np
def adjust_dynamic_range(image, percentiles=(1, 99)):
# Compute the lower and upper percentiles
lower_percentile, upper_percentile = np. percentile(image, percentiles)
# Clip the pixel values to the desired range
adjusted_image = np. clip(image, lower_percentile, upper_percentile)
# Normalize the pixel values to the full range [0, 255]
adjusted_image = cv2.normalize(adjusted_image, None, 0, 255,
cv2.NORM_MINMAX)
# Convert the pixel values to the appropriate data type
adjusted_image = adjusted_image.astype(np.uint8)
return adjusted_image
# Load the image
image = cv2.imread('input_image.jpg', cv2.IMREAD_COLOR)
# Convert the image to grayscale
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Adjust the dynamic range
adjusted_image = adjust_dynamic_range(gray_image, percentiles=(1, 99))
# Display the original and adjusted images
cv2.imshow('Original Image', gray_image)
cv2.imshow('Adjusted Image', adjusted_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
Noise Reduction
Using a Gaussian filter to smooth the image and decrease high-frequency noise is
known as noise reduction.
To reduce salt-and-pepper noise, median filtering replaces each pixel's value with the
median value of its neighbourhood.
Non-local Means Denoising: This method efficiently reduces many types of noise by
making use of the similarity of non-local image patches.
import cv2
def reduce_noise(image, kernel_size=(5, 5), sigmaX=0):
# Apply Gaussian blur to reduce noise
blurred_image = cv2.GaussianBlur(image, kernel_size, sigmaX)
return blurred_image
# Load the image
image = cv2.imread('input_image.jpg', cv2.IMREAD_COLOR)
# Reduce noise
noise_reduced_image = reduce_noise(image, kernel_size=(5, 5), sigmaX=0)
# Display the original and noise-reduced images
cv2.imshow('Original Image', image)
cv2.imshow('Noise-Reduced Image', noise_reduced_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
Conclusion
The improvement of visual quality, feature extraction, and subsequent analysis is made
possible by image enhancement techniques, which are essential to image processing
pipelines. Images can be efficiently improved for a variety of purposes by using
techniques including contrast enhancement, colour correction, noise reduction, and
dynamic range adjustment. Researchers and practitioners can optimise image quality,
extract valuable information, and unleash the full potential of images in a variety of
domains, from healthcare and remote sensing to computer vision and entertainment, by
understanding and utilising these techniques in image processing pipelines.
References
1. https://www.geeksforgeeks.org/image-enhancement-techniques-using-opencv-
python/
2. https://towardsdatascience.com/image-enhancement-techniques-using-opencv-and-python-
9191d5c30d45
3. https://www.mathworks.com/discovery/image-enhancement.html#:~:text=Image
%20enhancement%20is%20the%20process,easier%20to%20identify%20key%20features.
Do Checkout
1. The link to our product named AIEnsured offers explainability and many more
techniques
2. To know more about explainability and AI-related articles please visit this link.