侧边栏壁纸
博主头像
G

  • 累计撰写 85 篇文章
  • 累计创建 48 个标签
  • 累计收到 10 条评论

目 录CONTENT

文章目录

C图像Gamma校正

G
G
2021-03-04 / 0 评论 / 0 点赞 / 751 阅读 / 992 字 / 正在检测是否收录...
#include <math.h>

typedef unsigned char UNIT8; //用 8 位无符号数表示 0~255 之间的整数
UNIT8 g_GammaLUT[256];//全局数组:包含256个元素的gamma校正查找表
//Buildtable()函数对0-255执行如下操作:
//①归一化、预补偿、反归一化;
//②将结果存入 gamma 查找表。
//从公式得fPrecompensation=1/gamma
void BuildTable(float fPrecompensation ){
  int i;
  float f;
  for( i=0;i<256;i++)
  {
    f=(i+0.5F)/256;//归一化
    f=(float)pow(f,fPrecompensation);
    g_GammaLUT[i]=(UNIT8)(f*256-0.5F);//反归一化
  }
}

void GammaCorrectiom(UNIT8 src[],int iWidth,int iHeight,float fGamma,UNIT8 Dst[])
{
  int iCols,iRows;
  BuildTable(1/fGamma);//gamma校正查找表初始化
  //对图像的每个像素进行查找表矫正
  for(iRows=0;iRows<iHeight;iRows++)
  {
    for(iCols=0;iCols<iWidth;iCols++)
    {
	Dst[iRows*iWidth*3+iCols]=g_GammaLUT[src[iRows*iWidth*3+iCols]];
	Dst[iRows*iWidth*3+iCols+1]=g_GammaLUT[src[iRows*iWidth*3+iCols+1]];
	Dst[iRows*iWidth*3+iCols+2]=g_GammaLUT[src[iRows*iWidth*3+iCols+2]];
    }
  }
}

转载自:http://www.it165.net/pro/html/201603/63669.html

0

评论区