OpenCV the result of corrosion and swelling of the image

Source: Internet
Author: User

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

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.