Image pyramid and Its Application in opencv (below)

Source: Internet
Author: User

Preface

This article will mainly explain how to use opencv to achieve image segmentation, which is also an important application of image pyramid in opencv.

About Image Segmentation

In the field of computer vision, segmentation refers to the process of dividing digital images into multiple sub-regions (pixel sets) (also known as super pixels. Image segmentation aims to simplify or change the representation of an image, making it easier to understand and analyze the image. [1] image segmentation is usually used to locate objects and boundaries (lines, curves, etc.) in an image ). More precisely, image segmentation is a process of adding tags to each pixel in the image. This process makes pixels with the same tags have some common visual characteristics.

The result of image segmentation is a set of sub-areas on the image (all of these sub-areas cover the entire image), or a set of contour lines extracted from the image (such as edge detection ). Each pixel in a subarea is similar in terms of a feature metric or calculated characteristics, such as color, brightness, and texture. The adjacent area varies greatly with some feature measurements. [1]

------ Wikipedia

The following is a netizen's opinion on Image Segmentation technology, which is also worth learning from:

From an academic point of view, image segmentation is mainly divided into three categories: edge-based, region-based, and texture-based. Because texture-based data can also be viewed as region-based data, some experts also divide the data into two categories: edge-based data and region-based data. When selecting an algorithm, refer to the features of the image sample you want to split.

If the boundary of the image is very distinct, such as green leaves and safflower, the border can be precisely extracted from the red-green lines. In this case, the edge-based method is feasible. However, if the contour is not particularly obvious like a medical image, such as a heart image, the left atrium and left ventricular color are close, and the diaphragm between them is only a bit darker than the color, however, the color is very similar. At this time, the edge-based method is not suitable, and the region-based method is better. Another example is a texture-based image, such as a striped shirt. If we use the edge-based method, we may split each stripe into an object, but the clothes are actually a whole, at this time, the texture-based method can be used to divide the areas with the same or similar textures into a whole.

However, in general, the region-based method has become more popular in recent years, such as the meanshift segmentation method, the Dynamic Contour Model of the ground, and jseg.

------ A netizen

Pyramid image segmentation function-cvpyrsegmentation ()

Steps:

1. Create an image pyramid

2. Establish a parent-child relationship between the GI layer of the pyramid and the GI + 1 Layer

3. It is segmented and optimized layer by layer from a lower-resolution level to a higher-resolution level.

Function prototype:

1 void cvpyrsegmentation (2 iplimage * SRC, // input image 3 iplimage * DST, // output image 4 cvmemstorage * storage, // This parameter and the next parameter are used to manage detailed information about the split result. 5 cvseq ** comp, 6 int level, // pyramid level 7 double threshold1, // Error Threshold of establishing a connection 8 double threshold2 // Error Threshold of the split cluster 9 );

Special parameter descriptions:

1. the length and width of the input image must be divisible by 2, and the number of times the input image can be divisible by 2 is not less than the total number of layers of the pyramid.

2. The storage and comp parameters will be introduced in future articles based on specific development examples.

Reference sample code:

1 // This header file contains the declaration of image I/O functions 2 # include "highgui. H "3 // This header file contains basic image processing functions and advanced computer vision algorithms 4 # include" CV. H "5 // The cvpyrsegmentation splitting function must contain this header file 6 # include <opencv2/legacy. HPP> 7 8 # include <iostream> 9 Using namespace STD; 10 11 // split image 12 bool dopyrsegmentation (iplimage * SRC, iplimage * DST) 13 {14 // check whether the processed image size meets the specifications (for details about the specifications, refer to) 15 if (! (SRC-> width % 2 = 0 & Src-> height % 2 = 0) 16 return false; 17 18 // defines the split parameter 19 int level = 1; 20 double threshold1 = 150; 21 double threshold2 = 30; 22 cvmemstorage * stoage = cvcreatememstorage (0); 23 cvseq * comp = NULL; 24 25 // 26 cvpyrsegmentation (SRC, DST, stoage, & Comp, level, threshold1, threshold2); 27 28 return true; 29}; 30 31 int main (INT argc, char ** argv) 32 {33 iplimage * src = cvloadimage ("D: \ 1. Jpg "); 34 35 iplimage * DST = cvcreateimage (cvgetsize (SRC), Src-> depth, Src-> nchannels); 36 37 If (! Dopyrsegmentation (SRC, DST) {38 return exit_failure; 39} 40 41 cvnamedwindow ("before segmentation"); 42 cvnamedwindow ("after segmentation "); 43 cvshowimage ("before split", Src); 44 cvshowimage ("after split", DST); 45 46 cvwaitkey (0); 47 48 // clear memory 49 cvdestroyallwindows (); 50 51 return 0; 52}

Running result:

    

Summary

This article describes an example of image segmentation using opencv. As for how to obtain the specific results of the split for subsequent development, it will be discussed later.

 

Image pyramid and Its Application in opencv (below)

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.