Difference between revisions of "Short Notes on Wavelets"

From PaskvilWiki
Jump to: navigation, search
(Created page with "== Integer Haar Wavelets, Python implementation == This is a trivial implementation of Haar integer-to-integer wavelets. Note that resulting values typically use 1 more bit t...")
 
(Integer Haar Wavelets, Python implementation)
Line 4: Line 4:
 
Note that resulting values typically use 1 more bit than original ones - if source values are in [0..N) interval, then resulting values are in (-N, N) interval.
 
Note that resulting values typically use 1 more bit than original ones - if source values are in [0..N) interval, then resulting values are in (-N, N) interval.
  
=== Using Lists ===
+
In the following, ''d'' can be either ''list'', or ''numpy.array''.
  
 
<pre>def haar_int_fwd_1d(d):
 
<pre>def haar_int_fwd_1d(d):
Line 23: Line 23:
 
     hp = [i + j for i, j in zip(lp, odd)]
 
     hp = [i + j for i, j in zip(lp, odd)]
 
     return [x for t in zip(lp, hp) for x in t]</pre>
 
     return [x for t in zip(lp, hp) for x in t]</pre>
 
=== Using numpy array's ===
 
 
TBP
 

Revision as of 15:11, 24 February 2017

Integer Haar Wavelets, Python implementation

This is a trivial implementation of Haar integer-to-integer wavelets. Note that resulting values typically use 1 more bit than original ones - if source values are in [0..N) interval, then resulting values are in (-N, N) interval.

In the following, d can be either list, or numpy.array.

def haar_int_fwd_1d(d):
    if len(d) == 1:
        return d
    even = d[::2]
    odd = d[1::2]
    hp = [j - i for i, j in zip(even, odd)]
    lp = [i + (w >> 1) + (w % 2) for i, w in zip(even, hp)]
    return haar_int_fwd_1d(lp) + hp
    
def haar_int_inv_1d(d):
    if len(d) == 1:
        return d
    even = haar_int_inv_1d(d[:len(d) >> 1])
    odd = d[len(d) >> 1:]
    lp = [i - (j >> 1) - (j % 2) for i, j in zip(even, odd)]
    hp = [i + j for i, j in zip(lp, odd)]
    return [x for t in zip(lp, hp) for x in t]