C++ opencv cross structural element

1.形態學運算與結構元素
形態學運算是針對二值圖像依據數學形態學(Mathematical Morphology)的集合論方法發展起來的圖像處理方法。數學形態學起源於巖相學對岩石結構的定量描述工作,近年來在數字圖像處理和機器視覺領域中得到了廣泛的應用,形成了一種獨特的數字圖像分析方法和理論。

結構元素可以簡單的定義爲像素的組合,在對應的像素上定義了原點(也稱錨點)。形態學濾波器的應用過程就是利用這個結構元素探測圖像中每個像素的操作過程。把某個像素設爲結構元素的錨點後,結構元素和圖像重疊部分的像素集合就是特定形態學運算的應用對象。結構元素原則上可以是任何形狀,但通常是一個簡單形狀,如正方形、圓形、菱形等,且把中心點作爲原點。

  • 1. Morphological operations and structural elements

    Morphological operation is an image processing method developed by means of Mathematical Morphology based on binary images.Mathematical morphology originated from the quantitative description of rock structure in petrography, and has been widely applied in the field of digital image processing and machine vision in recent years, forming a unique digital image analysis method and theory.

    A structural element can simply be defined as a combination of pixels, with an origin (also known as an anchor point) defined on the corresponding pixel.The application process of morphological filter is to use this structural element to detect the operation process of each pixel in the image.When a pixel is set as the anchor point of the structural element, the pixel set of the overlapping part of the structural element and the image is the application object of the specific morphological operation.The structural element can be of any shape in principle, but is usually a simple shape, such as a square, circle, diamond, etc., with the center point as the origin.

2.自定義結構元素

十字形結構元素:cross

  • 2. Customize structural elements

    Cross structural element: Cross

定義:

define:

cross(5, 5, CV_8U, Scalar(0));
//創建十字形元素
for (int i = 0; i < 5; i++)
{
	cross.at<uchar>(2, i) = 1;
	cross.at<uchar>(i, 2) = 1;
}

use to test:

Mat result;
//十字形膨脹
dilate(image, result, cross);
//十字形腐蝕
erode(result, result, cross);

imwrite("./cross.jpg",result);

result:

 I hope I can help you,If you have any questions, please  comment on this blog or send me a private message. I will reply in my free time. 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章