[Learning opencv] image corrosion, expansion, and open/closed operations

Source: Internet
Author: User

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:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.