histogram equalize an input image and write it out

本文介绍了一种图像处理技术——直方图均衡化的方法。该技术通过调整图像的像素值分布来改善图像对比度。文章详细展示了如何计算图像直方图、累积分布函数,并利用这些信息对图像进行转换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/***************************************************************************
* 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]];
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值