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

来源:互联网 发布:linux基础教学视频 编辑:程序博客网 时间:2024/05/17 03:41
//2013.9 eageldiao#ifdef HISTOGRAM_RGBunsigned int lut[256];unsigned intncount[256]={0},ncount1[256]={0},ncount2[256]={0};int nTemp;//bfor(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]];}}//gfor(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]];}}//rfor(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


0 0