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]];
}
* 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]];
}
相关文章推荐
- Android Build with Gradle and ProGuard : “The output jar must be specified after an input jar, or it
- 论文笔记:An End-to-End Trainable Neural Network for Image-based Sequence Recognition and Its Application
- Write a program to copy its input to its output, replacing each tab by \t, each backspace by \b, and each backslash by \\. This makes tabs and backspa
- Launch an NSTask and bring it to front
- Write a program that prints its input one word per line.
- Load, Modify, and Save an Image
- Struts has detected an unhandled exception: Messages: No result defined for action com.pb.ognl.action.UserAction2 and result input
- Given an integer, write a function to determine if it is a power of two
- Insider Computer Fraud: An In-depth Framework for Detecting and Defending against Insider IT Attacks
- AIDL 编译报can be an out parameter, so you must declare it as in, out or inout原因探究
- 16. 26. 3. 装入想要尺寸的图片 Load Image and scale it
- AIDL 编译报can be an out parameter, so you must declare it as in, out or inout原因探究
- Using Imagecache and CCK Imagefield to Add an Image in Drupal
- Given two strings s and t, write a function to determine if t is an anagram of s.
- C# pdf 缩放纸型-iTextSharp - read an existing pdf, resize it and then draw it on a new one
- I did an SDK update last night and it moved adb.exe. In its place it left a file called "adb_has_mov
- Get image from URL and save it
- AIDL 编译报can be an out parameter, so you must declare it as in, out or inout原因探究
- Noticed a strange thing the other day, a list has the property ItemCount and also an Items collection which has its own .Count b
- 【图像处理】图像强度变换、直方图均衡化(Image Intensity Transformations and Histogram Equalization)