您的位置:首页 > 其它

histogram equalize an input image and write it out

2014-04-14 21:57 225 查看
/***************************************************************************
* Func: histogram_equalize *
* *
* Desc: histogram equalize an input image and write it out *
* *
* Params: buffer - pointer to image in memory *
* number_of_pixels - total number of pixels in image *
***************************************************************************/
// http://wangzaiqiqi.taobao.com void histogram_equalize(image_ptr buffer, unsigned long number_of_pixels)
{
unsigned long histogram[256]; /* image histogram */
unsigned long sum_hist[256]; /* sum of histogram elements */
float scale_factor; /* normalized scale factor */
unsigned long i; /* index variable */
unsigned long sum; /* variable used to increment sum of hist */

/* clear histogram to 0 */
for(i=0; i<256; i++)
histogram[i]=0;

/* calculate histogram */
for(i=0; i<number_of_pixels; i++)
histogram[buffer[i]]++;

/* calculate normalized sum of hist */
sum = 0;
scale_factor = 255.0 / number_of_pixels;
for(i=0; i<256; i++)
{
sum += histogram[i];
sum_hist[i] = (sum * scale_factor) + 0.5;
}

/* transform image using new sum_hist as a LUT */
for(i=0; i<number_of_pixels; i++)
buffer[i] = sum_hist[buffer[i]];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐