areaOpen

MainPage

Description: This method implements the area-open filter. It removes all components with area (volume if it is a 3D image) smaller than a threshold n.

Constructor signature: MorphTreeAlpha.areaOpen(n)

Input:
  • n, int. Area threshold value. Every node with area < n will be contracted.

Output:

Python Implementation

1 def areaOpen(self, n):
2     """
3     Contracts all the nodes with area less than 'area'
4     """
5 
6     area = self.node_array[3,:]
7     self.prune(area <= n)
8     return self

Example

 1 from morph_tree_alpha 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.areaOpen(3)
25 
26 g= morph_tree.generateGraph()
27 mmgraphviz(g, title='Morph-tree after filtering the nodes with area <= 3')
/media/_xsb/iamxt/morph_tree_area_open/GRVIZ72638_001.png

Morph-tree

/media/_xsb/iamxt/morph_tree_area_open/GRVIZ72638_002.png

Morph-tree after filtering the nodes with area <= 3