Created
July 17, 2012 20:41
-
-
Save nigma/3131916 to your computer and use it in GitHub Desktop.
Reconstructing WP tree using nth level coefficients
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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