码迷,mamicode.com
首页 > 其他好文 > 详细

cvMorphologyEx 形态学操作:开闭运算,形态学梯度,礼帽和黑帽

时间:2014-08-14 21:09:10      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:cvmorphologyex 形态学操作 开闭运算 形态学梯度 礼帽和黑帽 opencv

1.开运算:CV_MOP_OPEN,先腐蚀(cvErode)再膨胀(cvDilate),去除亮点,可以将做了阀值化细胞图像的细胞分开

2.闭运算:CV_MOP_CLOSE,先膨胀(cvDilate)再cvErode,去除暗点

3.形态学梯度:cvDilate-cvErode,用于求边界

4.礼帽:src-开运算,突出亮点

5.黑帽:闭运算-src,突出暗点

程序:

bubuko.com,布布扣

代码:

#include "cv.h"

#include "cxcore.h"

#include "highgui.h"

#include <iostream>

int morphology(int argc,char** argv)

{

IplImage* src=cvLoadImage("e:\\picture\\123.bmp",0);   //不一定要是黑白的 

IplImage* dst1=cvCreateImage(cvGetSize(src),src->depth,src->nChannels);

IplImage* dst2=cvCreateImage(cvGetSize(src),src->depth,src->nChannels);

IplImage* dst3=cvCreateImage(cvGetSize(src),src->depth,src->nChannels);

IplImage* dst4=cvCreateImage(cvGetSize(src),src->depth,src->nChannels);

IplImage* dst5=cvCreateImage(cvGetSize(src),src->depth,src->nChannels);

IplImage* temp=cvCreateImage(cvGetSize(src),src->depth,src->nChannels);

cvZero(dst1);

cvZero(dst2);

cvZero(dst3);

cvZero(dst4);

cvZero(dst5);

cvZero(temp);

cvNamedWindow("src");

cvNamedWindow("open");

cvNamedWindow("close");

cvNamedWindow("gradient");

cvNamedWindow("tophat");

cvNamedWindow("blackhat");

int value[]={1,1,1,

         1,1,1,

 1,1,1

};

IplConvKernel* kernel=cvCreateStructuringElementEx(3,3,1,1,CV_SHAPE_CUSTOM,value); //构建3*3的核

cvMorphologyEx(src,dst1,NULL,kernel,CV_MOP_OPEN,1); //开运算

cvMorphologyEx(src,dst2,NULL,kernel,CV_MOP_CLOSE,1); //闭运算

cvMorphologyEx(src,dst3,NULL,kernel,CV_MOP_GRADIENT,1);//形态学梯度

cvMorphologyEx(src,dst4,temp,kernel,CV_MOP_TOPHAT,1); //礼帽

cvMorphologyEx(src,dst5,temp,kernel,CV_MOP_BLACKHAT,1); //黑帽

cvShowImage("src",src);

cvShowImage("open",dst1);

cvShowImage("close",dst2);

cvShowImage("gradient",dst3);

cvShowImage("tophat",dst4);

cvShowImage("blackhat",dst5);

cvWaitKey(0);

cvDestroyWindow("src");

cvDestroyWindow("open");

cvDestroyWindow("close");

cvDestroyWindow("gradient");

cvDestroyWindow("tophat");

cvDestroyWindow("blackhat");

cvReleaseImage(&src);

cvReleaseImage(&dst1);

cvReleaseImage(&dst2);

cvReleaseImage(&dst3);

cvReleaseImage(&dst4);

cvReleaseImage(&dst5);

cvReleaseImage(&temp);

return 0;

}


本文出自 “flyclc” 博客,请务必保留此出处http://flyclc.blog.51cto.com/1385758/1539929

cvMorphologyEx 形态学操作:开闭运算,形态学梯度,礼帽和黑帽,布布扣,bubuko.com

cvMorphologyEx 形态学操作:开闭运算,形态学梯度,礼帽和黑帽

标签:cvmorphologyex 形态学操作 开闭运算 形态学梯度 礼帽和黑帽 opencv

原文地址:http://flyclc.blog.51cto.com/1385758/1539929

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!