OpenCV path exploration - morphological image processing (expansion, corrosion, opening, closing operation)

Erosion and dilation is the most basic morphological operations.

Erosion and dilation is for the purposes of the white part (highlights) of.

Expansion is performed on image highlights "field expansion", renderings have more than the original highlight region; Corrosion is highlighted areas in the artwork being eroded, have a smaller effect than the original FIG highlight region .

Swell

Expansion operation is seeking local maxima, from the image Intuitively, the image light is partially enlarged, dark part narrow.

#include<opencv2\opencv.hpp>   
#include<opencv2\highgui\highgui.hpp>

using namespace std;
using namespace cv;

//膨胀
int main()
{
    Mat img = imread("lol1.jpg");
    namedWindow("原始图", WINDOW_NORMAL);
    imshow("原始图", img);
    Mat out;
    //获取自定义核
    Mat element = getStructuringElement(MORPH_RECT, Size(15, 15)); //第一个参数MORPH_RECT表示矩形的卷积核,当然还可以选择椭圆形的、交叉型的
    //膨胀操作
    dilate(img, out, element);
    namedWindow("膨胀操作", WINDOW_NORMAL);
    imshow("膨胀操作", out);
    waitKey(0);

}

Can be seen, the original image is magnified bright portion, the dark portion is reduced.

corrosion

#include<opencv2\opencv.hpp>   
#include<opencv2\highgui\highgui.hpp>

using namespace std;
using namespace cv;

//腐蚀
int main()
{
    Mat img = imread("lol1.jpg");
    namedWindow("原始图", WINDOW_NORMAL);
    imshow("原始图", img);
    Mat out;
    //获取自定义核
    Mat element = getStructuringElement(MORPH_RECT, Size(15, 15)); //第一个参数MORPH_RECT表示矩形的卷积核,当然还可以选择椭圆形的、交叉型的
    //腐蚀操作
    erode(img, out, element);
    namedWindow("腐蚀操作", WINDOW_NORMAL);
    imshow("腐蚀操作", out);
    waitKey(0);

}

Can be seen, the original image is magnified portion of the dark and bright parts are reduced.

Open operation: etching first re-expansion, to eliminate small objects

Closing operation: the first expanded and corrosion, for excluding small black holes

Morphological gradient: difference in linear expansion is a plan view of the FIG., For retaining an object edge profile.

Top cap: the difference between the original image and the opening operation of the FIG., Adjacent to the lighting ratio for separating a number of plaques.

Black Hat: closing the difference between the original image and calculating, for a number of isolated plaques darker than adjacent points.

opencv there is a very good function getStructuringElement, as long as we pass this function to the appropriate processing parameters, it can be the appropriate action, and ease of use.

Listed below about the operation corresponding macro definition.

#include<opencv2\opencv.hpp>   
#include<opencv2\highgui\highgui.hpp>

using namespace std;
using namespace cv;

//高级形态学处理
int main()
{
    Mat img = imread("lol1.jpg");
    namedWindow("原始图", WINDOW_NORMAL);
    imshow("原始图", img);
    Mat out;
    //获取自定义核
    Mat element = getStructuringElement(MORPH_RECT, Size(15, 15)); //第一个参数MORPH_RECT表示矩形的卷积核,当然还可以选择椭圆形的、交叉型的
        
    //高级形态学处理,调用这个函数就可以了,具体要选择哪种操作,就修改第三个参数就可以了。这里演示的是形态学梯度处理
    morphologyEx(img, out, MORPH_GRADIENT, element);
    namedWindow("形态学处理操作", WINDOW_NORMAL);
    imshow("形态学处理操作", out);
    waitKey(0);

}

Morphological gradient processing

This is the top-hat operation effect

Published 352 original articles · won praise 115 · views 130 000 +

Guess you like

Origin blog.csdn.net/Aidam_Bo/article/details/104469163
Recommended