The function cvPyrSegmentation implements image segmentation by pyramids. The pyramid builds up to the level level. The links between any pixel a on level i and its candidate father pixel b on the adjacent level are established if
p(c(a),c(b))>threshold1. After the connected components are defined, they are joined into several clusters. Any two segments A and B belong to the same cluster, if
p(c(A),c(B))>threshold2. The input image has only one channel, then
p(c1,c2)=|c1-c2|. If the input image has three channels (red, green and blue), then
p(c1,c2)=0.3*(c1r-c2r)+0.59 * (c1g-c2g)+0.11 *(c1b-c2b) . There may be more than one connected component per a cluster.

C# | Visual Basic | Visual C++ |
public static void cvPyrSegmentation( IntPtr src, IntPtr dst, IntPtr storage, out IntPtr comp, int level, double threshold1, double threshold2 )

- src (IntPtr)
- The source image, should be 8-bit single-channel or 3-channel images
- dst (IntPtr)
- The destination image, should be 8-bit single-channel or 3-channel images, same size as src
- storage (IntPtr)
- Storage; stores the resulting sequence of connected components
- comp ( IntPtr %)
- Pointer to the output sequence of the segmented components
- level (Int32)
- Maximum level of the pyramid for the segmentation
- threshold1 (Double)
- Error threshold for establishing the links
- threshold2 (Double)
- Error threshold for the segments clustering