Chapter 5-image morphology-image pyramid-based image segmentation (cvpyrsegmentation)

Source: Internet
Author: User

This routine involves several data structures and methods, including cvmemstorage, cvpyrsegmentation (), cvconnectedcomp, and cvgetseqelem ().

 

Cvmemstorage

Cvmemstorage
Growing memory storage

Typedef struct cvmemstorage
{
Struct cvmemblock * bottom;/* first allocated block */
Struct cvmemblock * Top;/* The current memory block-top of the stack */
Struct cvmemstorage * parent;/* borrows new blocks from */
Int block_size;/* block size */
Int free_space;/* free space in the top block (in bytes )*/
} Cvmemstorage;
Memory is an underlying structure that can be used to store dynamic growth data structures such as sequences, outlines, graphs, and subpartitions. It consists of a series of memory blocks of the same size. The list-based bottom domain refers to the first column, and the top domain refers to the block currently pointed to, but not necessarily the end of the column. all blocks (including bottom, excluding top) between bottom and top are fully occupied; all blocks (including block tails, excluding top) between top and column tails) it is empty, while the top block itself occupies part of the space-free_space refers to the number of remaining empty words in the top block.

The newly allocated memory buffer (or explicitly allocated through the cvmemstoragealloc function, or implicitly allocated through cvseqpush, cvgraphaddedge, and other advanced functions) always starts from the current block (that is, the top block) if the remaining part can meet the requirements (the allocation size is sufficient ). After the allocation, free_space reduces the size of the newly allocated memory, and some additional sizes used to save the appropriate column type. When the remaining space of the top block cannot meet the size of the allocated block (buffer zone), the next storage block of the top block is set to the current block (New top block) -- free_space is set to the size of the entire block previously allocated.

If no empty storage block exists (that is, the top block is at the end of the column), you must assign a new block (or inherit from the parent, see cvcreatechildmemstorage) add the block to the end of the column. As a result, memory storage is like a stack. Bottom points to the bottom of the stack, and (top, free_space) points to the top of the stack. Stack top can be saved through cvsavemstoragepos, restored to point through cvrestoremstoragepos, and reset through cvclearstorage.

 

Cvpyrsegmentation

Pyrsegmentation
Use pyramid to achieve Image Segmentation

Void cvpyrsegmentation (iplimage * SRC, iplimage * DST,
Cvmemstorage * storage, cvseq ** comp,
Int level, double threshold1, double threshold2 );
SRC
Input image.
DST
Output image.
Storage
Storage: stores the sequence results of connected parts.
Comp
The output sequence pointer components of the split parts.
Level
Create the maximum number of layers of the pyramid
Threshold1
Connection establishment Error Threshold
Threshold2
Clustering Error Threshold
The cvpyrsegmentation function achieves Image Segmentation Using the pyramid method. The pyramid is created to the maximum number of layers specified by level. If P (C (A), C (B) <threshold1, the connection between the pixel point A of layer I and the parent pixel B of its adjacent layers is established,

After the connected parts are defined, they are added to some clusters. If P (C (A), C (B) <threshold2, then any two parts A and B belong to the same cluster.

If the input image has only one channel

P (C1, C2) = | c1-c2 |.
If the input image has a single channel (red, green, and blue), then

P (C1, C2) = · (c1r-c2r) + · (c1g-c2g) + · (c1b-c2b ).
Each cluster can have multiple connected parts. The image SRC and DST should be an 8-bit, single-channel, or 3-channel image with the same size

 

Cvconnectedcomp

Cvconnectedcomp
Connecting parts and connecting image parts

Typedef struct cvconnectedcomp
{
Double area;/* area of the connected domain */
Float value;/* The grayscale zoom value of the split domain */
Cvrect rect;/* segmentation region ROI */
} Cvconnectedcomp;

Cvgetseqelem

A function in opencv

Purpose: directly access the elements in the sequence.

Format: char * cvgetseqelem (SEQ, index)

Usage:

1. First, the returned char type pointer, of course, can also be converted to the actual data type stored in the sequence using forced type conversion.

Example: For (INT I = 0; I <seq-> total; ++ I)

{

Cvpoint * P = (cvpoint *) cvgetseqelem (SEQ, I );

}

2. seq is the sequence to be checked, while index is the index of the element in the sequence, that is, the first few elements.

 

/* The overall idea is to first split the image to form a contour of each part, and then connect each part of the image */

 

#include <cv.h>#include <stdio.h>#include 

/* Result */

 

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.