9. 对一幅对比度差的图像进行灰度均衡化。

#include 

#include 

#include 

IplImage* TO_junhenghua(IplImage *pImage);

int main(int argc, char** argv)

{

// 从文件中加载原图

IplImage *test = cvLoadImage("6013202130.jpg", CV_LOAD_IMAGE_UNCHANGED);

IplImage *test_1 = TO_junhenghua(test);

cvNamedWindow("原图", CV_WINDOW_AUTOSIZE);

cvNamedWindow("直方图均衡化后", CV_WINDOW_AUTOSIZE);

cvShowImage("原图", test);

cvShowImage("直方图均衡化后", test_1);

cvWaitKey(0);

cvDestroyWindow("原图");

cvDestroyWindow("直方图均衡化后");

cvReleaseImage(&test);

cvReleaseImage(&test_1);

return 0;

}

 

IplImage* TO_junhenghua(IplImage *pImage)

{

IplImage *pEquaImage = cvCreateImage(cvGetSize(pImage), pImage->depth, 3);

 

// 原图像分成各通道后再均衡化,最后合并即彩色图像的直方图均衡化

const int MAX_CHANNEL = 4;

IplImage *im_linshi[MAX_CHANNEL] = { NULL };

int i;

for (i = 0; i < pImage->nChannels; i++)

im_linshi[i] = cvCreateImage(cvGetSize(pImage), pImage->depth, 1);

cvSplit(pImage, im_linshi[0], im_linshi[1], im_linshi[2], im_linshi[3]);

for (i = 0; i < pImage->nChannels; i++)

cvEqualizeHist(im_linshi[i], im_linshi[i]);

cvMerge(im_linshi[0], im_linshi[1], im_linshi[2], im_linshi[3], pEquaImage);

for (i = 0; i < pImage->nChannels; i++)

cvReleaseImage(&im_linshi[i]);

return pEquaImage;

}

9. 对一幅对比度差的图像进行灰度均衡化。_第1张图片

你可能感兴趣的:(图像处理)