生物特征 高性能服务 智能交互分享 http://blog.sciencenet.cn/u/bluewind23 带着鲜刺的玫瑰刺得血如雨下一如既往前行!

博文

简单的去除光照影响:归一化RGB色彩模型

已有 11096 次阅读 2013-3-25 15:46 |个人分类:图像理解|系统分类:科研笔记| 色彩, 影响, 模型, 光照

IplImage* NormalizeImage(const IplImage *img)
 {
  if (!CV_IS_IMAGE(img) || !(IPL_DEPTH_8U ==img->depth) || !(3 == img->nChannels))
  {
   return NULL;
  }

  IplImage* imgavg = cvCreateImage(cvGetSize(img), img->depth, img->nChannels);
       
  if (!CV_IS_IMAGE(imgavg) )
  {
   return NULL;
  }

  int width = img->width;
  int height = img->height;
  int redValue, greenValue, blueValue;
  double sum, epslon = 0.000001;

  for (int y = 0; y < height; y++) 
  {
   for (int x = 0; x < width; x++) 
   {
    redValue =  ((uchar *)(img->imageData + y*img->widthStep))[x*img->nChannels + 2];
    greenValue =  ((uchar *)(img->imageData + y*img->widthStep))[x*img->nChannels + 1];
    blueValue =   ((uchar *)(img->imageData + y*img->widthStep))[x*img->nChannels + 0];
    sum = redValue + greenValue + blueValue + epslon;
    ((uchar *)(imgavg->imageData + y*imgavg->widthStep))[x*imgavg->nChannels + 2] = redValue / sum * 255;
    ((uchar *)(imgavg->imageData + y*imgavg->widthStep))[x*imgavg->nChannels + 1] = greenValue / sum * 255;
    ((uchar *)(imgavg->imageData + y*imgavg->widthStep))[x*imgavg->nChannels + 0] = blueValue / sum * 255;
   }
  }     
 
  return imgavg;
 }

 



https://blog.sciencenet.cn/blog-297739-673820.html

上一篇:Non Local means
下一篇:about HTTP chunked+gzip
收藏 IP: 61.140.169.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-24 19:18

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部