在这里,我们想向大家解释这本书的数字图像处理对冈萨雷斯的扩大和使用腐蚀-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处最小值来取代当前像素点的值。
二:书中定义
膨胀: .
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvTHU1OTcyMDM5MzM=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" >这里的B是结构元。B~是结构元的反射。反射不明确能够看书,就是旋转或者按中心点对称。如:
0 1 的反射就是 1 1
1 1 1 0
与opencv中唯一的差别就是必须得求反射,而opencv中则直接用给定的结构元B。
腐蚀:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvTHU1OTcyMDM5MzM=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" >
案例:
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvTHU1OTcyMDM5MzM=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" >
作者:小村长 出处:http://blog.csdn.net/lu597203933 欢迎转载或分享,但请务必声明文章出处。
(新浪微博:http://weibo.com/2653613245/profile , 欢迎交流!
)
版权声明:本文博主原创文章,博客,未经同意不得转载。