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

图像形态学操作—腐蚀扩展深度

时间:2015-09-29 14:25:59      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:

在这里,我们想向大家解释这本书的数字图像处理对冈萨雷斯的扩大和使用腐蚀-definedopencv取得的成果,然后控制它们之间的差异。

一:opencv达到

       在这之前能够看我的另外一篇blog:http://blog.csdn.net/lu597203933/article/details/17184439

膨胀:

案例代码:

int main()
{
	int a[8][8] = {
		{0,0,0,0,0,0,0,0}, 
		{0,0,5,1,0,0,1,1}, 
		{0,1,0,1,0,1,0,0},
		{0,1,1,2,1,0,1,0},
		{0,0,0,1,0,1,0,0},
		{0,1,0,0,0,0,0,1},
		{0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0}
	};
	Mat S = Mat::zeros(8, 8, CV_8UC1);
	for(int j = 0; j < S.rows; j++)
	{
		for(int i = 0; i < S.cols; i++)
		{
			S.at<uchar>(j,i) = a[j][i];
		}
	}
	cout << "S = " << endl << " " << S << endl;
	Mat result;
	Mat dilated = Mat::zeros(3, 3, CV_8UC1);
	dilated.at<uchar>(0,1) = 1;
	//eroded.at<uchar>(0,2) = 1;
	dilated.at<uchar>(1,0) = 1;
	dilated.at<uchar>(1,1) = 2;          // 结构元素非0即1
	dilated.at<uchar>(1,2) = 1;
	dilated.at<uchar>(2,1) = 1;
	cout << "dilated = " << endl << " " << dilated << endl;	
	dilate(S, result, dilated);  
	cout << "result = " << endl << " " << result << endl;
	return 0;
}

结果:

技术分享

膨胀就是假设结构元B有一处非0,而A相应位置非0,则求出A中与B中相应非0处所有像素最大值来取代当前像素点值。Opencv中默认的结构元是3*3的矩阵,所有非0。

腐蚀:

案例代码:

int main()
{
	int a[8][8] = {
		{0,0,0,0,0,0,0,0}, 
		{0,0,5,1,0,0,1,1}, 
		{0,1,0,1,0,1,0,0},
		{0,1,1,2,1,0,1,0},
		{0,0,0,1,0,1,0,0},
		{0,1,0,0,0,0,0,1},
		{0,0,0,0,0,0,0,0},
		{0,0,0,0,0,0,0,0}
	};
	Mat S = Mat::zeros(8, 8, CV_8UC1);
	for(int j = 0; j < S.rows; j++)
	{
		for(int i = 0; i < S.cols; i++)
		{
			S.at<uchar>(j,i) = a[j][i];
		}
	}
	cout << "S = " << endl << " " << S << endl;
	Mat result;
	Mat eroded = Mat::zeros(3, 3, CV_8UC1);
	eroded.at<uchar>(0,1) = 1;
	//eroded.at<uchar>(0,2) = 1;
	eroded.at<uchar>(1,0) = 1;
	eroded.at<uchar>(1,1) = 2;          // 结构元素非0即1
	eroded.at<uchar>(1,2) = 1;
	eroded.at<uchar>(2,1) = 1;
	cout << "eroded = " << endl << " " << eroded << endl;	
	erode(S, result, eroded);  
	cout << "result = " << endl << " " << result << endl;
	return 0;

结果:

技术分享

腐蚀就是结构元B处非0,则A相应位置也全非0。且取全非0处最小值来取代当前像素点的值。

 

二:书中定义

膨胀: . 技术分享这里的B是结构元。B~是结构元的反射。反射不明确能够看书,就是旋转或者按中心点对称。如:

0 1   的反射就是 1 1

1 1                        1 0

与opencv中唯一的差别就是必须得求反射,而opencv中则直接用给定的结构元B。

腐蚀: 技术分享

案例:

技术分享


作者:小村长  出处:http://blog.csdn.net/lu597203933 欢迎转载或分享,但请务必声明文章出处。 (新浪微博:http://weibo.com/2653613245/profile , 欢迎交流!


版权声明:本文博主原创文章,博客,未经同意不得转载。

图像形态学操作—腐蚀扩展深度

标签:

原文地址:http://www.cnblogs.com/yxwkf/p/4846061.html

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