[mmMaxgetindex] [Up] [mmMaxgetchildren] Introspection Functions

mmMaxgetnodes
Returns node properties.

Synopsis

Image mmMaxgetnodes ( const MaxTree& maxtree , const Double& level , const Double& index = -1 );

Input

maxtree MaxTree

The MaxTree.

level Double

Node level.

index Double

Node index. If not specified or negative, the function returns properties for all nodes in the given level.

Default: -1

Output

y Image

Properties of the node(s). Each row contains the following properties:

  • [0] isleaf: is this a leaf node?
  • [1] level: parent node level
  • [2] index: parent node index
  • [3] area: node area (number of pixels)
  • [4] sum_x: x_centroid = sum_x / area
  • [5] sum_y: y_centroid = sum_y / area
  • [6] xmin: minimum x coordinate
  • [7] ymin: minimum y coordinate
  • [8] xmax: maximum x coordinate
  • [9] ymax: maximum y coordinate
  • [10] height: node height
  • [11] volume: node volume

Description

This function returns the properties of the given node, if index is specified, or the properties for all nodes in a given level, if index is not specified or is negative.

Call mmMaxgetcount before this function to avoid accessing inexistent nodes.

Examples

unsigned char _a[21] = {1, 2, 3, 4, 4, 4, 3, 2, 3, 5, 6, 6, 4, 4, 4, 3, 3, 4, 1, 2, 2};
Image a(21, 1, 1, "uint8", (char *)_a);
MaxTree mt = mmMaxtree(a);
Image nn = mmMaxgetcount(mt);
for(int i = 0; i < 256; i++) {
    if(nn.getpixel(i, 0, 0) > 0) {
        printf("----------\nLevel: %d\n", i);
        Image nodes = mmMaxgetnodes(mt, i);
        int ***ptr = (int ***)nodes.pointers();
        for(int j = 0; j < nodes.height(); j++) {
            printf("    -\n");
            printf("    isleaf:       %d\n", ptr[0][j][0]);
            printf("    parent level: %d\n", ptr[0][j][1]);
            printf("    parent index: %d\n", ptr[0][j][2]);
            printf("    area:         %d\n", ptr[0][j][3]);
            printf("    height:       %d\n", ptr[0][j][10]);
            printf("    volume:       %d\n", ptr[0][j][11]);
            printf("    centroid:     (%d, %d)\n", ptr[0][j][4]/ptr[0][j][3], ptr[0][j][5]/ptr[0][j][3]);
            printf("    bounding box: (%d, %d) - (%d, %d)\n", ptr[0][j][6], ptr[0][j][7], ptr[0][j][8], ptr[0][j][9]);
        }
    }
}
        

----------
Level: 1
    -
    isleaf:       0
    parent level: 0
    parent index: -1
    area:         21
    height:       7
    volume:       70
    centroid:     (10, 0)
    bounding box: (0, 0) - (20, 0)
----------
Level: 2
    -
    isleaf:       0
    parent level: 1
    parent index: 0
    area:         17
    height:       5
    volume:       47
    centroid:     (9, 0)
    bounding box: (1, 0) - (17, 0)
    -
    isleaf:       1
    parent level: 1
    parent index: 0
    area:         2
    height:       1
    volume:       2
    centroid:     (19, 0)
    bounding box: (19, 0) - (20, 0)
----------
Level: 3
    -
    isleaf:       0
    parent level: 2
    parent index: 0
    area:         5
    height:       2
    volume:       8
    centroid:     (4, 0)
    bounding box: (2, 0) - (6, 0)
    -
    isleaf:       0
    parent level: 2
    parent index: 0
    area:         10
    height:       4
    volume:       22
    centroid:     (12, 0)
    bounding box: (8, 0) - (17, 0)
----------
Level: 4
    -
    isleaf:       1
    parent level: 3
    parent index: 0
    area:         3
    height:       1
    volume:       3
    centroid:     (4, 0)
    bounding box: (3, 0) - (5, 0)
    -
    isleaf:       0
    parent level: 3
    parent index: 1
    area:         6
    height:       3
    volume:       11
    centroid:     (11, 0)
    bounding box: (9, 0) - (14, 0)
    -
    isleaf:       1
    parent level: 3
    parent index: 1
    area:         1
    height:       1
    volume:       1
    centroid:     (17, 0)
    bounding box: (17, 0) - (17, 0)
----------
Level: 5
    -
    isleaf:       0
    parent level: 4
    parent index: 1
    area:         3
    height:       2
    volume:       5
    centroid:     (10, 0)
    bounding box: (9, 0) - (11, 0)
----------
Level: 6
    -
    isleaf:       1
    parent level: 5
    parent index: 0
    area:         2
    height:       1
    volume:       2
    centroid:     (10, 0)
    bounding box: (10, 0) - (11, 0)

[mmMaxgetindex] [Up] [mmMaxgetchildren]