直方图均衡化 EqualizeHist

核心函数:

cvEqualizeHist

程序:

wKioL1PsKKTB5HsEAAK67-Z4OD0352.jpg

#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include <iostream>
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;
}


你可能感兴趣的:(opencv,直方图均衡化,EqualizeHist)