Image processing of converting gamma opencv

 

import cv2
import numpy as np
img=cv2.imread('4.jpg')
def adjust_gamma(image, gamma=1.0):
    invGamma = 1.0/gamma
    table = []
    for i in range(256):
        table.append(((i / 255.0) ** invGamma) * 255)
    table = np.array(table).astype("uint8")
    return cv2.LUT(image, table)

img_gamma = adjust_gamma(img, 2)
cv2.imshow("img",img)
cv2.imshow("img_gamma",img_gamma)

key = cv2.waitKey()
if key == 27:
    cv2.destroyAllWindows()

 

 

 

 


 

Mentioned LUT, a lot of people will probably think this is a very professional and very deep vocabulary, LUT is actually an abbreviation Look Up Table (color lookup table), the simple little understood is this: through LUT, we can output a set of RGB values another set of RGB values, thereby changing the exposure and color screen. LUT file that contains a matrix of data input can change the color information. LUT operation itself is not performed, which include simply a series of input and output data to, the data was one to one relationship, the system in accordance with this correspondence relationship for each input value to an output value of the lookup corresponding thereto, i.e., so the reason can complete the conversion, but also the LUT basically do not consume CPU resources.
Original link: https: //blog.csdn.net/weixin_42171170/article/details/94473176


Mentioned LUT, a lot of people will probably think this is a very professional and very deep vocabulary, LUT is actually an abbreviation Lookup Table (color lookup table), the simple little understood is this: through LUT, you can output a set of RGB values another set of RGB values, thereby changing the exposure and color screen. Using a simple model helps us to understand is this:

If we stipulate:

When the original value of R 0, the output value of R 5;

When the original value of R 1, R output value of 6;

When the original value of R 2, the output value of R 8;

When the original value of R 3, R output value of 10;

...

R is up to 255

When the original value of G 0, G is the output 10;

When the original value of G 1, G output value of 12;

When the original value of G 2, G output value of 13;

When the original value of G 3, G output value of 15;

...

G is up to 255

When the original value of B 0, B output value is 0;

When the original value of B 1, B is 0 output;

When the original B is 2, the output value B 1;

3 B when the original value, the output B is 1;

...

B is up to 255

Then, after the output value if a pixel RGB (1,2,3), it applied this LUT is RGB (6,13,1), so we can put all the original RGB values ​​into RGB output value. Of course, in actual 3D LUT conversion algorithm which is much more complex than that.

Original link: http: //www.sohu.com/a/230989286_252971


 

 

There is a reference article: https: //blog.csdn.net/Rothwale/article/details/79189032


 

Guess you like

Origin www.cnblogs.com/yibeimingyue/p/11455233.html