Function iahaarmatrix

Synopse

Kernel matrix for the Haar Transform.

  • A = iahaarmatrix(N)
    • A: Image.
    • N: Double.
01. from numpy import *
02. 
03. def iahaarmatrix(N):
04.     from iameshgrid import iameshgrid
05. 
06.     n = floor(log(N)/log(2))
07. 
08.     if 2**n != N:
09.        raise Exception, 'error: size '+str(N)+' is not multiple of power of 2'
10. 
11.     z, k = iameshgrid(1.*arange(N)/N, 1.*arange(N))
12.     p  = floor(log(maximum(1,k))/log(2))
13.     q  = k - (2**p) + 1
14.     z1 = (q-1)   / (2**p)
15.     z2 = (q-0.5) / (2**p)
16.     z3 = q       / (2**p)
17.     A  = (1/sqrt(N)) * ((( 2**(p/2.)) * ((z >= z1) & (z < z2))) \
18.                               + ((-2**(p/2.)) * ((z >= z2) & (z < z3))))
19.     A[0,:] = 1/sqrt(N)
20.     return A

Examples

Example 1

1. from ia636 import iahaarmatrix, ianormalize
2. 
3. A = iahaarmatrix(128)
4. adshow(ianormalize(A,[0,255]))

Example 2

1. A = iahaarmatrix(4)
2. print A
3. print dot(A, transpose(A))
[[ 0.5         0.5         0.5         0.5       ]
 [ 0.5         0.5        -0.5        -0.5       ]
 [ 0.70710678 -0.70710678  0.          0.        ]
 [ 0.          0.          0.70710678 -0.70710678]]
[[ 1.  0.  0.  0.]
 [ 0.  1.  0.  0.]
 [ 0.  0.  1.  0.]
 [ 0.  0.  0.  1.]]