opencv —— erode、dilate 腐蝕與膨脹


腐蝕與膨脹是形態學濾波。其中,腐蝕是最小值濾波,膨脹是最大值濾波,即分別選取內核中的最小值與最大值賦值給錨點。若內核為 N×1 或 1×N 形狀,可用於橫縱方向直線檢測。

膨脹:dilate 函數

void dilate (InputArray src, OutputArray dst, InputArray kernel, Point anchor = Point(-1, -1), int iterations = 1, int borderType = BORDER_CONSTANT, const Scalar& borderValue = morphologyDefaultBorderValue());

  • src,輸入圖像,即原圖像,填 Mat 類的對象即可。
  • dst,目標圖像,需要和原圖片有一樣的尺寸和類型。
  • kernel,膨脹操作的核。當為 NULL 時,表示的是使用參考點位於中心,大小 3×3 的核。

一般用函數 getStructuringElement 配合這個參數使用。

例如:Mat kernel = getStructuringElement(MORPH_RECT, Size(3, 3));

Mat getStructuringElement(int shape, Size ksize, Point anchor = Point(-1, -1));

    • shape,矩形:MORPH_RECT

交叉形:MORPH_CROSS

橢圓形:MORPH_ELLIPSE

    • ksize,內核的尺寸。
    • anchor,錨點的位置,默認位於中心。
  • anchor,錨點的位置,默認位於中心。
  • iterations 迭代使用 dilate() 的次數,默認值為 1。
  • borderType,邊界拓展的方法。
  • borderValue,當邊界為常數時的邊界值,有默認值,一般不用管。

 

腐蝕:erode 函數

void erode(InputArray src, OutputArray dst, InputArray kernel, Point anchor = Point(-1, -1), int iterations = 1, int borderType = BORDER_CONSTANT, const Scalar& borderValue = morphologyDefaultBorderValue());

  • 成員函數意義幾乎和 dilate 一致

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM