伽马校正(Gamma Correction)

伽马校正(Gamma Correction)

为什么需要伽马校正?

部分人认为,是由于早期CRT显示器的输出亮度和输入电压存在非线性关系,具体就是近似2.2次幂的关系,导致显示器的亮度要比计算机上存储的亮度要低。

举个例子:假如你计算机存储的亮度是0.5(亮度范围是0~1),CRT显示器的输出亮度并不是0.5,而是约等于 0.218,具体计算过程如下
o u t p u t = i n p u t 2.2 output = input^{2.2} output=input2.2
当你输入0.5时,输出到显示器的值为
o u t p u t = 0. 5 2.2 ≈ 0.218 output = 0.5^{2.2} \approx 0.218 output=0.52.20.218
其中2.2这个指数就是伽马值,而显示器的这种非线性输出过程称为伽马展开(gamma expansion)。

为了能够得到正确的输出,必须对输入进行补偿,方法是对输入进行一次指数为1/2.2的幂次运算,这个补偿的过程就是伽马校正:

i n p u t ⟶ i n p u t 1 2.2 input \longrightarrow input^{\frac{1}{2.2}} inputinput2.21
经过伽马校正后,显示器便能正确显示我们的输入了 :
{ i n p u t ⟶ i n p u t 1 2.2 o u t p u t = ( i n p u t 1 2.2 ) 2.2 = i n p u t \left\{ \begin{aligned} input& \longrightarrow input^{\frac{1}{2.2}} \\ output& = (input^{\frac{1}{2.2}})^{2.2} = input \end{aligned} \right. { input

  • 11
    点赞
  • 48
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要编写正伽马校正(Positive Gamma Correction),需要进行以下步骤: 1. 设置伽马值:正伽马校正是一种非线性的校正方法,通过将像素值的平方根或其它次方应用于原始像素值来调整图像亮度。伽马值通常在1.8到2.5之间,可以根据实际需要进行调整。 2. 计算伽马校正表:将每个像素值进行伽马校正,生成一个伽马校正表。可以使用以下公式进行计算:Gamma-corrected value = Original value^(1/Gamma)。 3. 应用伽马校正:将伽马校正表应用于图像中的所有像素,以生成正伽马校正的图像。 下面是一个使用ESP32和libili9341库的示例代码,用于进行正伽马校正: ```c++ #include <Adafruit_GFX.h> #include <Adafruit_ILI9341.h> #define TFT_CS 10 #define TFT_DC 9 #define TFT_RST 8 // Create a new instance of the display library Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST); float gammaValue = 2.2; // Set gamma value for positive gamma correction void setup() { // Initialize the display tft.begin(); } void loop() { // Load image data into a buffer uint16_t buffer[320 * 240]; for (int i = 0; i < 320 * 240; i++) { buffer[i] = /* load pixel data */; } // Generate gamma correction table uint8_t gammaTable[256]; for (int i = 0; i < 256; i++) { gammaTable[i] = pow(i / 255.0, gammaValue) * 255.0 + 0.5; } // Apply gamma correction to image data for (int i = 0; i < 320 * 240; i++) { uint16_t pixel = buffer[i]; uint8_t r = (pixel & 0xF800) >> 11; uint8_t g = (pixel & 0x07E0) >> 5; uint8_t b = pixel & 0x001F; r = gammaTable[r]; g = gammaTable[g]; b = gammaTable[b]; buffer[i] = (r << 11) | (g << 5) | b; } // Display the image tft.startWrite(); tft.setAddrWindow(0, 0, 319, 239); tft.pushColors(buffer, 320 * 240); tft.endWrite(); } ``` 在这个示例中,我们使用了ESP32和libili9341库来控制显示屏。我们首先加载图像数据到一个缓冲区中,然后使用伽马值计算一个伽马校正表。最后,我们将伽马校正表应用于图像数据,并将结果显示在显示屏上。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值