zoukankan      html  css  js  c++  java
  • [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
    
  • 相关阅读:
    把一个数组 赋值给一个新数组
    上传图片时进行压缩
    input上传文件 显示进度条
    vue 后台接口返回文件流地址的下载
    时间戳转换
    JS 两个含有部分相同属性的对象如何快速给对应的key赋值
    javascript中把一个数组的内容全部赋值给另外一个数组
    微信小程序wxs如何使用
    优化内存
    解决position:fiexd相对父元素定位
  • 原文地址:https://www.cnblogs.com/eaglediao/p/7136507.html
Copyright © 2011-2022 走看看