<s> from aonlm import firdn <EOL> import numpy as np <EOL> from cshift3D import cshift3D <EOL> def permutationInverse ( perm ) : <EOL> inverse = [ <NUM_LIT:0> ] * len ( perm ) <EOL> for i , p in enumerate ( perm ) : <EOL> inverse [ p ] = i <EOL> return inverse <EOL> def afb3D_A ( x , af , d ) : <EOL> lpf = af [ : , <NUM_LIT:0> ] <EOL> hpf = af [ : , <NUM_LIT:1> ] <EOL> p = [ ( i + d ) % <NUM_LIT:3> for i in xrange ( <NUM_LIT:3> ) ] <EOL> x = x . transpose ( p ) <EOL> ( N1 , N2 , N3 ) = x . shape <EOL> L = af . shape [ <NUM_LIT:0> ] // <NUM_LIT:2> <EOL> x = cshift3D ( x , - L , <NUM_LIT:0> ) ; <EOL> n1Half = N1 // <NUM_LIT:2> <EOL> lo = np . zeros ( ( L + n1Half , N2 , N3 ) ) ; <EOL> hi = np . zeros ( ( L + n1Half , N2 , N3 ) ) ; <EOL> for k in xrange ( N3 ) : <EOL> lo [ : , : , k ] = firdn ( x [ : , : , k ] , lpf ) ; <EOL> lo [ : L ] = lo [ : L ] + lo [ n1Half : n1Half + L , : , : ] ; <EOL> lo = lo [ : n1Half , : , : ] ; <EOL> for k in xrange ( N3 ) : <EOL> hi [ : , : , k ] = firdn ( x [ : , : , k ] , hpf ) ; <EOL> hi [ : L ] = hi [ : L ] + hi [ n1Half : n1Half + L , : , : ] ; <EOL> hi = hi [ : n1Half , : , : ] ; <EOL> q = permutationInverse ( p ) <EOL> lo = lo . transpose ( q ) <EOL> hi = hi . transpose ( q ) <EOL> return lo , hi <EOL> def afb3D ( x , af1 , af2 = None , af3 = None ) : <EOL> if af2 == None : <EOL> af2 = af1 <EOL> if af3 == None : <EOL> af3 = af1 <EOL> L , H = afb3D_A ( x , af1 , <NUM_LIT:0> ) ; <EOL> LL , LH = afb3D_A ( L , af2 , <NUM_LIT:1> ) ; <EOL> HL , HH = afb3D_A ( H , af2 , <NUM_LIT:1> ) ; <EOL> LLL , LLH = afb3D_A ( LL , af3 , <NUM_LIT:2> ) ; <EOL> LHL , LHH = afb3D_A ( LH , af3 , <NUM_LIT:2> ) ; <EOL> HLL , HLH = afb3D_A ( HL , af3 , <NUM_LIT:2> ) ; <EOL> HHL , HHH = afb3D_A ( HH , af3 , <NUM_LIT:2> ) ; <EOL> return LLL , [ LLH , LHL , LHH , HLL , HLH , HHL , HHH ] </s>
