Parent/S max-tree implementation

C++ Code

OK

SWIG header

OK [C/C++ extension is up-to-date]

Python Wrapper

01. import numpy as np
02. from iamxt.max_tree_c_01 import counting_sort_c, union_find2d_c, canonicalize_c
03. from iamxt.se2off import se2off
04. 
05. def max_tree_par_S(f, Bc):
06.     off = se2off(Bc) # Array of offsets
07.     parent = np.empty(f.size, dtype = np.int32)
08.     parent[:] = -1
09.     zpar = np.empty(f.size, dtype = np.int32)
10.     flat_img = f.ravel()
11.     S_rev = counting_sort_c(flat_img)
12.     H,W = f.shape
13.     union_find2d_c(H,W,off,parent,zpar,S_rev,flat_img)
14.     canonicalize_c(flat_img,parent,S_rev)
15.     return parent,S_rev
16. 
17. def compute_area(S,parent):
18.     area = np.ones(S.size, dtype = np.int32)
19.     compute_area_c(S,parent,area)
20.     return area
21. 
22. def compute_height(S,parent,f):
23.     height = np.zeros(S.size, dtype = np.int32)
24.     compute_height_c2(S,parent,f.ravel(),height)
25.     return height
26. 
27. def direct_filter(lambda_,S,parent,img,attr):
28.     flat_img = np.ascontiguousarray(img.ravel())
29.     out = np.empty(S.size, dtype = np.uint8)
30.     direct_filter_c(lambda_,S,parent,flat_img,out,attr.astype(float))
31.     return out.reshape(img.shape)
1. pass