zoukankan      html  css  js  c++  java
  • 形态学处理

     本文的主角是OpenCV中的morphologyEx函数,它利用基本的膨胀和腐蚀技术,来执行更加高级的形态学变换,如开闭运算、形态学梯度、“顶帽”、“黑帽”等等

    void cv::morphologyEx( InputArray _src,OutputArray _dst, int op,
                 InputArray kernel, Pointanchor, int iterations,
                 int borderType, constScalar& borderValue )
    {
    //拷贝Mat数据到临时变量
       Mat src = _src.getMat(), temp;
       _dst.create(src.size(), src.type());
       Mat dst = _dst.getMat();
     
    //一个大switch,根据不同的标识符取不同的操作
       switch( op )
      {
       case MORPH_ERODE: //腐蚀
         erode( src, dst, kernel, anchor, iterations, borderType, borderValue );
         break;
       case MORPH_DILATE: //膨胀
         dilate( src, dst, kernel, anchor, iterations, borderType, borderValue );
         break;
       case MORPH_OPEN:  //开环
         erode( src, dst, kernel, anchor, iterations, borderType, borderValue );
         dilate( dst, dst, kernel, anchor, iterations, borderType, borderValue );
         break;
       case CV_MOP_CLOSE: //闭环
         dilate( src, dst, kernel, anchor, iterations, borderType, borderValue );
         erode( dst, dst, kernel, anchor, iterations, borderType, borderValue );
         break;
       case CV_MOP_GRADIENT://梯度
         erode( src, temp, kernel, anchor, iterations, borderType, borderValue );
         dilate( src, dst, kernel, anchor, iterations, borderType, borderValue );
         dst -= temp;
         break;
       case CV_MOP_TOPHAT: //顶帽  即是原图像与开运算后的图像相减
         if( src.data != dst.data )
           temp = dst;
         erode( src, temp, kernel, anchor, iterations, borderType, borderValue );
        dilate( temp, temp, kernel, anchor,iterations, borderType, borderValue );
         dst = src - temp;
         break;
       case CV_MOP_BLACKHAT: //黑帽  即是闭运算后的图像减去原图像
         if( src.data != dst.data )
           temp = dst;
         dilate( src, temp, kernel, anchor, iterations, borderType, borderValue);
         erode( temp, temp, kernel, anchor, iterations, borderType, borderValue);
         dst = temp - src;
         break;
       default:
         CV_Error( CV_StsBadArg, "unknown morphological operation" );
      }
    }

    • MORPH_OPEN – 开运算(Opening operation)
    • MORPH_CLOSE – 闭运算(Closing operation)
    • MORPH_GRADIENT -形态学梯度(Morphological gradient)
    • MORPH_TOPHAT - “顶帽”(“Top hat”)
    • MORPH_BLACKHAT - “黑帽”(“Black hat“)
     膨胀与腐蚀的介绍可以参考这篇文章http://www.cnblogs.com/slysky/archive/2011/10/16/2214015.html
  • 相关阅读:
    图解Python 【第八篇】:网络编程-进程、线程和协程
    TCP协议三次握手、四次挥手过程
    OSI七层模型与TCP/IP五层模型
    TCP/IP协议分为哪四层,具体作用是什么。
    app测试中,ios和android的区别
    APP在用户设备发生crash,应该怎么修复
    Android四层架构
    安卓四大组件、六大布局、五大存储
    测试工程师准备找工作,需要准备什么?
    接口测试响应码解析
  • 原文地址:https://www.cnblogs.com/haoxing990/p/4577225.html
Copyright © 2011-2022 走看看