MaxTreeAlpha Class Constructor

MainPage

Description: Constructor of the class MaxTreeAlpha.

Signature: MaxTreeAlpha.__init__(img = None, Bc = None)

Input:
  • img: uint8 or uint16 2D or 3D numpy array. When working with 1D signals use an array or
  • Bc: bool, Array corresponding to the connectivity to be used during the tree construction. The convention is that coordinates (0,0) or (0,0,0) are in the center of the array.

Output:

Example: 2D

 1 from iamxt.max_tree_alpha import MaxTreeAlpha
 2 import numpy as np
 3 
 4 img = np.array([[9,10, 3, 3, 3, 5, 8],
 5                 [2, 0, 4, 0, 0, 0, 7],
 6                 [8, 0, 5, 0, 6, 0, 9],
 7                 [9, 0, 6, 0, 8, 4, 2]],dtype = np.uint8)
 8 
 9 print "2D test image:\n", img
10 
11 Bc = np.array([[1,1,1],\
12                [1,1,1],\
13                [1,1,1]], dtype = bool)
14 
15 print "\n2D structuring Element Bc:\n", Bc.astype(int)
16 
17 mxt = MaxTreeAlpha(img,Bc)
18 print '\nNode_array:\n', mxt.node_array
19 print '\nNode_index:\n', mxt.node_index
2D test image:
[[ 9 10  3  3  3  5  8]
 [ 2  0  4  0  0  0  7]
 [ 8  0  5  0  6  0  9]
 [ 9  0  6  0  8  4  2]]

2D structuring Element Bc:
[[1 1 1]
 [1 1 1]
 [1 1 1]]

Node_array:
[[ 0  0  1  1  3  3  4  4  5  5  8  6  7 11 11  2  9]
 [ 1  2  1  2  2  2  1  1  1  1  0  2  0  0  0  0  0]
 [ 0  2  8  3  4  4  5  6  5  9  6  7  8  9  8  9 10]
 [28 19  2 15  7  5  4  2  2  2  1  3  1  1  1  1  1]
 [ 8  7 14  2 26  9  5 18 16  0 23 13 25 20  6 21  1]
 [42 26  5 17 11  6  3  5  5  0  3  3  3  2  0  3  0]
 [ 0  0  2  0  0  0  0  2  2  0  3  0  3  2  0  3  0]
 [ 3  3  3  3  3  3  2  3  3  0  3  2  3  2  0  3  0]
 [84 58  0 52 36  7 23  8  4  1  2 18  4  6  6  0  1]
 [ 0  0  0  0  4  0  5  4  2  0  2  6  4  6  6  0  1]
 [ 6  6  0  6  6  2  6  4  2  1  2  6  4  6  6  0  1]]

Node_index:
[[ 9 16  3  3  3  6 14]
 [ 1  0  5  0  0  0 11]
 [ 2  0  8  0  7  0 13]
 [15  0 10  0 12  4  1]]

Example: 3D

 1 # Creating a simple 3D image example
 2 img2 = np.zeros((5,5,5), dtype = np.uint8)
 3 img2[2,1:-1,1:-1] = 1
 4 img2[2,2,2] = 2
 5 img2[1,1:-1,1:-1] = 1
 6 img2[3,1:-1,1:-1] = 1
 7 
 8 print "3D test image:\n", img2
 9 
10 Bc2 = np.ones((3,3,3), dtype = bool)
11 print "3D structuring element:\n", Bc2.astype(int)
12 
13 mxt2 = MaxTreeAlpha(img2,Bc2)
14 print '\nNode_array:\n', mxt2.node_array
15 print '\nNode_index:\n', mxt2.node_index
3D test image:
[[[0 0 0 0 0]
  [0 0 0 0 0]
  [0 0 0 0 0]
  [0 0 0 0 0]
  [0 0 0 0 0]]

 [[0 0 0 0 0]
  [0 1 1 1 0]
  [0 1 1 1 0]
  [0 1 1 1 0]
  [0 0 0 0 0]]

 [[0 0 0 0 0]
  [0 1 1 1 0]
  [0 1 2 1 0]
  [0 1 1 1 0]
  [0 0 0 0 0]]

 [[0 0 0 0 0]
  [0 1 1 1 0]
  [0 1 1 1 0]
  [0 1 1 1 0]
  [0 0 0 0 0]]

 [[0 0 0 0 0]
  [0 0 0 0 0]
  [0 0 0 0 0]
  [0 0 0 0 0]
  [0 0 0 0 0]]]
3D structuring element:
[[[1 1 1]
  [1 1 1]
  [1 1 1]]

 [[1 1 1]
  [1 1 1]
  [1 1 1]]

 [[1 1 1]
  [1 1 1]
  [1 1 1]]]

Node_array:
[[  0   0   1]
 [  1   1   0]
 [  0   1   2]
 [125  27   1]
 [  0  31  62]
 [250  54   2]
 [  0   1   2]
 [  4   3   2]
 [250  54   2]
 [  0   1   2]
 [  4   3   2]
 [250  54   2]
 [  0   1   2]
 [  4   3   2]]

Node_index:
[[[0 0 0 0 0]
  [0 0 0 0 0]
  [0 0 0 0 0]
  [0 0 0 0 0]
  [0 0 0 0 0]]

 [[0 0 0 0 0]
  [0 1 1 1 0]
  [0 1 1 1 0]
  [0 1 1 1 0]
  [0 0 0 0 0]]

 [[0 0 0 0 0]
  [0 1 1 1 0]
  [0 1 2 1 0]
  [0 1 1 1 0]
  [0 0 0 0 0]]

 [[0 0 0 0 0]
  [0 1 1 1 0]
  [0 1 1 1 0]
  [0 1 1 1 0]
  [0 0 0 0 0]]

 [[0 0 0 0 0]
  [0 0 0 0 0]
  [0 0 0 0 0]
  [0 0 0 0 0]
  [0 0 0 0 0]]]