Default corrosion and expansion operation:
#include <QCoreApplication> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp > #include <opencv2/imgproc/imgproc.hpp>using namespace cv;int main () { Mat src = imread ("Lena.jpg", 0); Mat DST, eroded, dilated; Mat Element (7, 7, cv_8u, Scalar (1)); Threshold (SRC, DST, 255, THRESH_BINARY_INV);//binary image value Namedwindow ("DST", 0); Imshow ("DST", DST); Erode (DST, eroded, Mat ());//Corrosion Namedwindow ("eroded", 0); Imshow ("eroded", eroded); Dilate (DST, dilated, Mat ());//Swell Namedwindow ("dilated", 0); Imshow ("dilated", dilated); Waitkey (0);}
Function Description:
1. The threshold function is used to process the grayscale image into two-valued image, the first parameter is the input grayscale image, the second parameter is the output two value image, the third parameter is the threshold value, the fourth parameter is the data that satisfies the threshold condition of the pixel, and the fifth parameter is the positive and negative switch. There is also a thresh_binary, the opposite effect.
After the strength factor has been added:
#include <QCoreApplication> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp > #include <opencv2/imgproc/imgproc.hpp>using namespace cv;int main () { Mat src = imread ("Lena.jpg", 0); Mat DST, eroded, dilated; Mat Element (7, 7, cv_8u, Scalar (1)); Threshold (SRC, DST, 255, THRESH_BINARY_INV); Namedwindow ("DST", 0); Imshow ("DST", DST); Erode (DST, eroded, element); Namedwindow ("eroded", 0); Imshow ("eroded", eroded); Dilate (DST, dilated, Element); Namedwindow ("dilated", 0); Imshow ("dilated", dilated); Waitkey (0);}
Function Description:
1, Element matrix is the strength of corrosion and expansion, here is the structure of 7*7 elements.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Qt 5.3 under OpenCV 2.4.11 Development (13) Corrosion and expansion