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


    #include <opencv2/opencv.hpp>
    
    #include <highgui.h>
    
    #include <cv.h>
    
    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;
    
    }

  • 相关阅读:
    linux下配置php的一些信息
    前端学习
    Verilog笔记.3.有限状态机
    Verilog笔记.2.数字逻辑电路
    Verilog笔记.1.基本语法
    python3爬虫.4.下载煎蛋网妹子图
    python3爬虫.3.下载网页图片
    python3爬虫.2.伪装浏览器
    python3爬虫.1.简单的网页爬虫
    python3学习笔记.3.条件控制与循环
  • 原文地址:https://www.cnblogs.com/zhangfeionline/p/5465208.html
Copyright © 2020-2023  润新知