In the digital image processing, the morphological transformation of the image occupies a very important position. Basic morphological transformations are swelling and corrosion, which can be implemented in a variety of functions, such as eliminating noise, splitting separate image elements, and connecting adjacent elements in an image. Of course, morphology is also used to find out the gradient of the image.
I. Introduction to KEY functionshere is the introductionOpenCVThe key function of binary image in
Cverode ()
function function: Corrosion of the image
Function prototypes:void Cverode (const cvarr* SRC, cvarr* DST, iplconvkernel* element=null, int iterations=1);
Function Description:
SRC: Input image. DST: Output image. Element: structural elements for corrosion. If NULL, use a 3x3 rectangular structure element iterations: number of corrosioncvdilate ()function Function: Expands the imagefunction Prototypes:void cvdilate (const cvarr* SRC, cvarr* DST, iplconvkernel* element=null, int iterations=1); Function Description: srcenter an image.DstThe output image.Elementstructure element. If NULL, the default 3x3 rectangle is used, the anchor point is in the middle of the structure element, and the expansion operation is performedIterationsNumber of expansionsTwo. Sample program code
#include <opencv2/opencv.hpp> #include <iostream>using namespace std;using namespace Cv;const char * Pstrsrcwindowstitle = "original"; const char *pstrdestwindowstitle_1 = "After the original is corroded"; const char *pstrdestwindowstitle_2 = "After the original is inflated" const char *pstrdestwindowstitle_3 = "bloat of corroded images"; int main (int argc, char *argv[]) {iplimage * src_image = Cvloadimage (arg V[1]);//Load Picture Cvnamedwindow (Pstrdestwindowstitle_1, cv_window_autosize);//Create window to display Cvnamedwindow ( Pstrsrcwindowstitle, cv_window_autosize); Cvshowimage (Pstrsrcwindowstitle, src_image);//display Original// Create two image spaces to store the transformed picture Iplimage * out_image = Cvcreateimage (Cvgetsize (src_image), ipl_depth_8u,3); Iplimage * out_image_2 = Cvcreateimage (Cvgetsize (src_image), ipl_depth_8u,3); Cvdilate (Src_image, Out_image, NULL, 2);//expansion processing, and display cvshowimage ( Pstrdestwindowstitle_2, Out_image); Cverode (Src_image, out_image,null,2);//corrosion treatment, and display cvshowimage ( Pstrdestwindowstitle_1, Out_image); Cvdilate (Out_image, out_image_2, NULL, 2);//re-expansion of corroded images cvshowimage ( Pstrdestwindowstitle_3, out_image_2); Waitkey (0); return 0;}
OpenCV the result of corrosion and swelling of the image