You are on page 1of 3

ILLUMINATION CORRECTION

DONE BY:Abhimanyu Gulati


Nitin Kumar
Jaivardhan Singh

VARIOUS METHODS

Illumination correction is a preprocessing step in image processing that aims to


compensate for non-uniform illumination across an image. Uneven illumination can
affect the quality and accuracy of image analysis tasks such as object detection,
segmentation, and recognition. Here are some common illumination correction
methods:

​ Flat-Field Correction: Flat-field correction is a simple method to correct for


non-uniform illumination by dividing the image by a reference or "flat-field" image.
The flat-field image is typically acquired by capturing an image of a uniform light
source. This method helps to remove shading effects caused by uneven
illumination.
Example: Let's say you have an image I and a flat-field image F. The corrected
image C is obtained by dividing I by F: C = I / F.
​ Homomorphic Filtering: Homomorphic filtering is a technique that can be used to
correct both illumination and reflectance variations in an image. It is particularly
useful for images with strong variations in illumination. The method works in the
logarithmic domain by dividing the image into two components: the illumination
component and the reflectance component. The illumination component is
adjusted to be more uniform, while the reflectance component is preserved.
Example: Given an input image I, the homomorphic filtering process involves
taking the logarithm of the image, applying a high-pass filter in the frequency
domain to enhance the illumination variations, and then exponentiating the result
to obtain the corrected image.
​ Histogram Equalization: Histogram equalization is a technique that aims to
enhance the contrast of an image by redistributing the pixel values across the
intensity range. This can be useful for correcting images with non-uniform
illumination. It stretches the histogram of the image to cover the entire intensity
range.
Example: Given an input image I, histogram equalization involves calculating the
cumulative distribution function (CDF) of the pixel intensities, mapping the CDF
to the desired intensity range, and applying the mapping function to each pixel.
​ Retinex Models: Retinex models are a family of methods that aim to separate an
image into its reflectance and illumination components. These methods assume
that the reflectance component is mostly independent of illumination variations.
Different variants of Retinex models exist, including single-scale and multi-scale
approaches.
Example: The simplest form of Retinex correction involves applying a logarithmic
transform to the image and subtracting a blurred version of the logarithmic
image. This helps in enhancing edges and details while minimizing the effect of
non-uniform illumination.
​ Vignetting Correction: Vignetting is a common form of illumination variation that
causes the image to be brighter at the center and darker at the edges. Vignetting
correction methods aim to remove this effect. These methods often involve
estimating a correction function that describes the radial intensity variation and
applying it to the image.
Example: One approach to vignetting correction is to capture a flat-field image of
a uniform surface and use it as a reference for correction. The captured image is
divided by the flat-field image to obtain the corrected image.

EXAMPLE

import cv2
import numpy as np

def illumination_correction(image_path, gamma=0.5, cutoff_frequency=32):


# Load the image in grayscale
img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)

# Apply logarithmic transformation to the image


img_log = np.log1p(np.array(img, dtype="float") / 255)

# Perform Fourier Transform


f = np.fft.fft2(img_log)

# Apply Gaussian high-pass filter to remove low-frequency components


rows, cols = img.shape
center_row, center_col = rows // 2, cols // 2
mask = np.zeros((rows, cols))
mask[center_row - cutoff_frequency:center_row + cutoff_frequency,
center_col - cutoff_frequency:center_col + cutoff_frequency] = 1
f_shift = f * mask

# Perform Inverse Fourier Transform


img_back = np.fft.ifft2(f_shift)
img_back = np.real(img_back)

# Apply exponential transformation and rescale to [0, 255]


img_exp = np.expm1(img_back)
img_corrected = (img_exp - np.min(img_exp)) / (np.max(img_exp) - np.min(img_exp)) * 255

# Apply gamma correction to enhance contrast


img_corrected = img_corrected ** gamma

return img_corrected.astype(np.uint8)

# Example usage
input_image_path = "input.jpg"
output_image_path = "output.jpg"
corrected_image = illumination_correction(input_image_path, gamma=0.5,
cutoff_frequency=32)
cv2.imwrite(output_image_path, corrected_image)
print("Illumination correction complete. Output image saved as", output_image_path)

OUTPUT

You might also like