[code]彩色图像直方图均衡化 histogram_rgb

//2013.9 eageldiao
#ifdef HISTOGRAM_RGB
unsigned int lut[256];
unsigned intncount[256]={0},ncount1[256]={0},ncount2[256]={0};
int nTemp;
//b
for(y=0;yheight;y++)
{
unsigned char *srcrow= (unsignedchar*)(src->imageData+y*src->widthStep);
for (x=0;xwidth;x++)
{   
ncount[srcrow[3*x]]++;               //统计灰度级数量
}
}
for (int i=0;i<256;i++)             
{
nTemp=0;
for (int j=0;j<=i;j++)
{
nTemp+=ncount[j];
}
lut[i]=nTemp*255/src->width/src->height;//确定变换函数
}
for(y=0;yheight;y++)               //均衡化
{
unsigned char *srcrow= (unsignedchar*)(src->imageData+y*src->widthStep);
for (x=0;xwidth;x++)
{  
srcrow[3*x]=lut[srcrow[3*x]];
}
}
//g
for(y=0;yheight;y++)                //统计灰度级 数量
{
unsigned char *srcrow= (unsignedchar*)(src->imageData+y*src->widthStep);
for (x=0;xwidth;x++)
{   
ncount1[srcrow[3*x+1]]++;
}
}

for (int i=0;i<256;i++)             
{
nTemp=0;
for (int j=0;j<=i;j++)
{
nTemp+=ncount1[j];
}
lut[i]=nTemp*255/src->width/src->height; //确定变换函数
}

for(y=0;yheight;y++)                 //均衡化
{
unsigned char *srcrow= (unsignedchar*)(src->imageData+y*src->widthStep);
for (x=0;xwidth;x++)
{  
srcrow[3*x+1]=lut[srcrow[3*x+1]];
}
}

//r
for(y=0;yheight;y++)                  //统计灰度级 数量
{
unsigned char *srcrow= (unsignedchar*)(src->imageData+y*src->widthStep);
for (x=0;xwidth;x++)
{   
ncount2[srcrow[3*x+2]]++;
}
}
for (int i=0;i<256;i++)             
{
nTemp=0;
for (int j=0;j<=i;j++)
{
nTemp+=ncount2[j];
}
lut[i]=nTemp*255/src->width/src->height;//确定变换函数
}
for(y=0;yheight;y++)                //均衡化
{
unsigned char *srcrow= (unsignedchar*)(src->imageData+y*src->widthStep);
for (x=0;xwidth;x++)
{  
srcrow[3*x+2]=lut[srcrow[3*x+2]];
}
}
#endif


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值