核心函数:

cvEqualizeHist

程序:

#include "cv.h"#include "cxcore.h"#include "highgui.h"#include 
int EqualizeHist(int argc,char** argv){IplImage* src=cvLoadImage("e:\\picture\\4.jpg");IplImage* SrcB=cvCreateImage(cvGetSize(src),8,1);IplImage* SrcG=cvCreateImage(cvGetSize(src),8,1);IplImage* SrcR=cvCreateImage(cvGetSize(src),8,1);IplImage* DstB=cvCreateImage(cvGetSize(src),8,1);IplImage* DstG=cvCreateImage(cvGetSize(src),8,1);IplImage* DstR=cvCreateImage(cvGetSize(src),8,1);IplImage* Result=cvCreateImage(cvGetSize(src),8,3);cvSplit(src,SrcB,SrcG,SrcR,NULL);  //把彩***分成B,G,R三个灰度图,因为cvEqualizeHist只能处理单通道图像cvEqualizeHist(SrcB,DstB);  //直方图均衡化cvEqualizeHist(SrcG,DstG);cvEqualizeHist(SrcR,DstR);cvMerge(DstB,DstG,DstR,NULL,Result);  //合并图像cvNamedWindow("src");cvNamedWindow("SrcB");cvNamedWindow("SrcG");cvNamedWindow("SrcR");cvNamedWindow("DstB");cvNamedWindow("DstG");cvNamedWindow("DstR");cvNamedWindow("Result");cvShowImage("src",src);cvShowImage("SrcB",SrcB);cvShowImage("SrcG",SrcG);cvShowImage("SrcR",SrcR);cvShowImage("DstB",DstB);cvShowImage("DstG",DstG);cvShowImage("DstR",DstR);cvShowImage("Result",Result);cvWaitKey(0);return 0;}