In [1]:
import numpy as np
def hadamard(f):
import ia898.src as ia
f = np.asarray(f).astype(np.float64)
if len(f.shape) == 1: f = f[:, newaxis]
(m, n) = f.shape
A = ia.hadamardmatrix(m)
if (n == 1):
F = np.dot(A, f)
else:
B = ia.hadamardmatrix(n)
F = np.dot(np.dot(A, f), np.transpose(B))
return F
In [2]:
testing = (__name__ == "__main__")
if testing:
! jupyter nbconvert --to python hadamard.ipynb
import numpy as np
import sys,os
import matplotlib.image as mpimg
ia898path = os.path.abspath('../../')
if ia898path not in sys.path:
sys.path.append(ia898path)
import ia898.src as ia
In [3]:
if testing:
f = mpimg.imread('../data/cameraman.tif')
F = ia.hadamard(f)
nb = ia.nbshow(2)
nb.nbshow(f)
nb.nbshow(ia.normalize(np.log(abs(F)+1)))
nb.nbshow()
In [ ]:
if testing:
f = mpimg.imread('../data/cameraman.tif')
print('Computational time is:')
%timeit ia.hadamard(f)
In [ ]: