Image Enhancement Techniques in an Image Processing


The visual appeal and overall efficiency of image processing pipelines are significantly improved by image enhancement. Using various methods and algorithms, image enhancement improves crucial visual elements, fixes flaws, and prepares images for further examination or presentation. This article examines various widely used image enhancement methods in image processing pipelines, emphasizing their importance and uses.

Contrast Enhancement:

Histogram equalization 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 Equalization (CLAHE): Controlling the contrast enhancement process to prevent noise from being amplified.

Image source- google

The code using the OpenCV library for contrast enhancement-

import cv2
import numpy as np
def enhance_contrast(image, alpha, beta):
# Perform contrast enhancement using the formula: output = alpha * input + beta
enhanced_image = cv2.convertScaleAbs(image, alpha=alpha, beta=beta)
return enhanced_image

Load the image

image = cv2.imread('input_image.jpg', cv2.IMREAD_COLOR)

Adjust the contrast parameters

alpha = 1.5 # Contrast control (1.0 for original image)
beta = 30 # Brightness control (0-100)

Enhance the contrast

enhanced_image = enhance_contrast(image, alpha, beta)

Display the original and enhanced images

cv2.imshow('Original Image', image)
cv2.imshow('Enhanced Image', enhanced_image)

Color Correction:

Correcting for color casts brought on by various lighting situations in order to restore proper color representation.

Color transfer: Aligning the color appearance by transferring color attributes from a reference image to the target image.

Color Constancy: Ensuring that colors 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)

Dynamic Range Adjustment:

By reducing the dynamic range for display on low-dynamic-range (LDR) devices, tone mapping improves the visibility of details in high-dynamic-range (HDR) photographs.

The fusion of numerous exposures of the same scene to produce an image with a greater dynamic range and more accurate details is known as exposure.

Image source- google

The code using the OpenCV library for Dynamic Range Adjustment

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)

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.

Image source- google

The code using the OpenCV library for Noise Reduction

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)


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.

Do Checkout:

The link to our product named AIensured offers explainability and many more techniques.

To know more about explainability and AI-related articles please visit this link.