Code to use gamma correction in image using colorchart.
Reference:
TAKAHASHI, Masato et al. Development of a camera-based remote diagnostic system focused on color reproduction using color charts. Artificial life and robotics, v. 25, p. 370-376, 2020.
Using a calibrated colorchart image, it's possible to adjust a gamma function to correct the image. The adjustment of the function takes into consideration the reference RGB values of the colorchart and the values of the image.
Note: the colorchart must be properly aligned in the image to accurately obtain the values of each patch in the image.
For a different colorchart, the average RGB values of each grayscale patch, ranging from black to white, must be added to a .csv file in column (A) -(/reference_RGB_Logitech_gray.csv/)
.
In this work, the RGB values of each patch were acquired using a colorimeter (Delta Color).
L*a*b
values were acquired for each grayscale patch and transformed into RGB.
In Excel ((/reference_RGB_Logitech_gray.csv/)
), save the average RGB values of each patch, the first value of the blackest patch and the last value of the white patch.
For analysis, the code -getColorchart2.py
reads the grayscale values of the 6 patches and compares them with the expected values.
The according the reference [TAKAHASHI, Masato et al.]
First, we extract the color chart part of the photograph using AR markers. The portions of each square are further taken and averaged. The model is created through a multiple regression from the difference between the averaged numbers and the reference RGB values. Based on this, all pixels are converted to correct the color of the human face and tongue.
The details of the gamma correction are next described. First, such correction is applied based on the luminance of the grayscale portion of the color chart measured by a colorimeter against the RGB value when the grayscale was photographed. Similarly, this is also conducted for the grayscale portion of the reference RGB value. Next, a gamma correction is applied for each RGB. In the case of R, the form is as shown in Eq:
where Rc is the R-value of the image taken, and Y is the luminance of the color chart’s grayscale. In the grayscale of the color chart, the brightness of the grayscale is transformed to within the range of zero to 1 by normalizing with the brightness value of white such that black has a value zero and white has a value of 1. This model can be used to correct the gamma for any RGB value. Specifically, we compute the gamma-corrected RGB values by multiplying the inverse function of Eq. (6) for each value.
Next, we construct a model using multiple regression on the color of each gamma-corrected color patch. In the case of R, we have Eq.:
where R'c is the R value of the corrected image and Rr, Gr, Br indicate an un-corrected RGB value. Each parameter is calculated by a multiple regression with every color patch.
Finally, the color correction is completed by performing a transformation on each pixel of the captured image