Files » gammaCorrector.py
| 1 |
import cv2 as cv |
|---|---|
| 2 |
import numpy as np |
| 3 |
|
| 4 |
##
|
| 5 |
# @file gamma_corrector.py
|
| 6 |
# @brief This script defines the GammaCorrector class, which is used for applying gamma correction to images.
|
| 7 |
#
|
| 8 |
|
| 9 |
##
|
| 10 |
# @class GammaCorrector
|
| 11 |
# @brief A class for performing gamma correction on images.
|
| 12 |
#
|
| 13 |
class GammaCorrector: |
| 14 |
##
|
| 15 |
# @fn __init__(self, gamma)
|
| 16 |
# @brief Constructor for GammaCorrector.
|
| 17 |
# @param gamma The gamma value for correction.
|
| 18 |
#
|
| 19 |
def __init__(self, gamma): |
| 20 |
self.gamma = gamma |
| 21 |
|
| 22 |
##
|
| 23 |
# @fn gamma_correction(self, image)
|
| 24 |
# @brief Applies gamma correction to the image by certain equations.
|
| 25 |
# @param image The image to be gamma corrected.
|
| 26 |
# @return Gamma corrected image.
|
| 27 |
#
|
| 28 |
def gamma_correction(self, image): |
| 29 |
# Create a lookup table for gamma correction.
|
| 30 |
lut = np.array([((i / 255.0) ** (1 / self.gamma)) * 255 for i in np.arange(256)]).astype(np.uint8) |
| 31 |
# Apply the gamma correction using OpenCV's LUT function.
|
| 32 |
return cv.LUT(image, lut) |
| 33 |
|
| 34 |
# Save this class in a file named gamma_corrector.py
|