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
{
for (int x = 0; 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;
}
转载本文请联系原作者获取授权,同时请注明本文来自张建成科学网博客。
链接地址:http://blog.sciencenet.cn/blog-297739-673820.html
上一篇:Non Local means
下一篇:about HTTP chunked+gzip