数字图像的直方图均衡化是常用的图像增强方法,因为均衡化是自动完成的,无需人工干预,而且常常得到比较满意的结果。下面的程序是利用OPENCV提供的函数,实现这个功能。需要OPENCV B4.0的支持,在VC6下编译通过。
//
// perform histgram equalization for single channel image
// AssureDigit Sample code
//
#include "cv.h"
#include "highgui.h"
#define HDIM 256 // bin of HIST, default = 256
int main( int argc, char** argv )
{
IplImage *src = 0, *dst = 0;
CvHistogram *hist = 0;
int n = HDIM;
double nn[HDIM];
uchar T[HDIM];
CvMat *T_mat;
int x;
int sum = 0; // sum of pixels of the source image 图像中象素点的总和
double val = 0;
if( argc != 2 || (src=cvLoadImage(argv[1], 0)) == NULL) // force to gray image
return -1;
cvNamedWindow( "source", 1 );
cvNamedWin