Basic morphological operations of images.
# Include "CV. H "# include" highgui. H "using namespace CV; int main (INT argc, char * argv []) {mat src = imread (" misaka.jpg "); mat dst; // input image // output image // unit size, which is a 5*5 8-bit unit // corrosion location, negative value: Obtain the core center // The number of times the erode (SRC, DST, MAT (5, 5, cv_8u), point (-1,-1), 2 ); imwrite ("erode.jpg", DST); // input image // output image // unit size, which is a 5*5 8-bit unit // expansion position, negative value: Obtain the kernel center. // The number of expansion times is twice. (SRC, DST, MAT (5, cv_8u), point (-1,-1), 2 ); imwrite ("dilate.jpg", DST); // input image // output image // define the operation: morph_open indicates the on operation, and morph_close indicates the closed operation // unit size, here is the 8-bit unit of 3*3 // the location of the open/closed operation // The number of open/closed operations morphologyex (SRC, DST, morph_open, MAT (3, 3, cv_8u), point (-1, -1), 1); imwrite ("open.jpg", DST); morphologyex (SRC, DST, morph_close, MAT (3,3, cv_8u), point (-1,-1 ), 1); imwrite ("close.jpg", DST); imshow ("DST", DST); waitkey (); Return 0 ;}
Source image:
5*5 unit corrosion twice:
5*5 unit expansion twice:
3*3 unit operation:
3*3 unit closed operation once: