14. 对一幅二值图像进行膨胀、腐蚀、开运算和闭运算,观察效果。

#include <stdio.h>
#include <cv.h>
#include <highgui.h>
#include <cvaux.h> 

int main(void)
{
    int i = 40;
    IplImage *img = cvLoadImage("6013202130.bmp", 0);
    IplImage *imga = cvLoadImage("xibao.jpg", 0);
    IplImage *oo_fushi = cvCreateImage(cvGetSize(img), 8, 1);
    IplImage *oo_pengzhang = cvCreateImage(cvGetSize(img), 8, 1);
    IplImage *oo_kai = cvCreateImage(cvGetSize(imga), 8, 1);
    IplImage *oo_bi = cvCreateImage(cvGetSize(imga), 8, 1);
    cvErode(img, oo_fushi, NULL, 1); //腐蚀图像
    cvDilate(img, oo_pengzhang, NULL, 1); //膨胀图像
    cvMorphologyEx(imga, oo_kai, NULL, NULL, CV_MOP_OPEN,1);//开运算
    cvMorphologyEx(imga, oo_bi, NULL, NULL, CV_MOP_CLOSE,3);//闭运算
    cvNamedWindow("原图");
    cvNamedWindow("腐蚀后");
    cvNamedWindow("膨胀后");
    cvNamedWindow("开运算后");
    cvNamedWindow("闭运算后");
    cvShowImage("原图",img);
    cvShowImage("腐蚀后", oo_fushi);
    cvShowImage("膨胀后", oo_pengzhang);
    cvShowImage("开运算后", oo_kai);
    cvShowImage("闭运算后", oo_bi);
    cvWaitKey(-1);
    cvReleaseImage(&oo_pengzhang);
    cvReleaseImage(&oo_fushi);
    cvReleaseImage(&oo_kai);
    cvReleaseImage(&oo_bi);
    cvDestroyAllWindows();
    return 0;
}

posted @ 2016-05-06 13:05  张飞online  阅读(1960)  评论(0编辑  收藏  举报