bbox

MainPage

Description: This method implements the bbox filter. It removes all components with a bounding-box with dimensions smaller than dx, dy, and dz in case of 3D images.

Constructor signature: MorphTreeAlpha.bbox(dx, dy, dz = 0)

Input:
  • dx, int. dx threshold value.
  • dy, int. dy threshold value.
  • dz, int. dz threshold value, its value is considered only in the case of 3D images.

Output:

Python Implementation

 1 def bbox(self, dx, dy, dz = 0):
 2     """
 3     Contracts all nodes with bounding box less than 'dx' by 'dy'
 4     """
 5     ddx = self.node_array[7,:] - self.node_array[6,:] + 1
 6     ddy = self.node_array[10,:] - self.node_array[9,:] + 1
 7     if self.node_index.ndim == 2:
 8         self.prune((ddx < dx) & (ddy < dy))
 9     else:
10         ddz = self.node_array[13,:] - self.node_array[12,:] + 1
11         self.prune((ddx < dx) & (ddy < dy) & (ddz < dz))
12     return self

Example

 1 from iamxt import MorphTreeAlpha
 2 import numpy as np
 3 
 4 img = np.array([[100, 100, 100, 0,   0,   0,   0,   0],\
 5                 [150, 150, 150, 150, 150, 150, 150, 150],\
 6                 [150, 160, 190, 150, 200, 200, 229, 150], \
 7                 [150, 185, 255, 150, 200, 230, 200, 150],\
 8                 [150, 180, 200, 150, 215, 229, 200, 150],\
 9                 [150, 150, 150, 150, 150, 150, 150, 150],\
10                 [50,  50,  0,   0,   0,   0,   0,   0]], dtype = np.uint8)
11 
12 
13 Bc = np.array([[0,1,0],\
14                [1,1,1],\
15                [0,1,0]], dtype = bool)
16 
17 
18 morph_tree = MorphTreeAlpha(img,Bc)
19 
20 g= morph_tree.generateGraph()
21 mmgraphviz(g, title='Morph-tree')
22 
23 morph_tree = MorphTreeAlpha(img,Bc)
24 morph_tree.bbox(dx = 2, dy = 2)
25 
26 g= morph_tree.generateGraph()
27 mmgraphviz(g, title='Morph-tree after filtering the nodes with dx < 2 and dy < 2')
/media/_xsb/iamxt/morph_tree_bbox/GRVIZ95539_001.png

Morph-tree

/media/_xsb/iamxt/morph_tree_bbox/GRVIZ95539_002.png

Morph-tree after filtering the nodes with dx < 2 and dy < 2