Skip to content

Instantly share code, notes, and snippets.

@nigma
Created July 17, 2012 20:41
Show Gist options
  • Save nigma/3131916 to your computer and use it in GitHub Desktop.
Save nigma/3131916 to your computer and use it in GitHub Desktop.
Reconstructing WP tree using nth level coefficients
def get_node_paths(level=1):
"""
Lists node paths on the given level.
Order of the paths is the same as order of nodes
returned by `WaveletPacket2D.get_leaf_nodes`.
"""
paths = [""]
for i in range(level):
paths = [
path + name
for path in paths
for name in pywt.Node2D.PARTS
]
return paths
# empty 2D WP tree
wp = pywt.WaveletPacket2D(data=None, wavelet=wavelet, maxlevel=level)
coefs = [...] # given
# set node data using corresponding coefficients
for i, path in enumerate(get_node_paths(level)):
wp[path] = coeff[i]
rec = wp.reconstruct(update=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment