In [1]:
import numpy as np
def dctmatrix(N):
x = np.resize(range(N), (len(range(N)), len(range(N)))) #matrix with columns index
u = np.transpose(np.resize(range(N), (len(range(N)), len(range(N))))) #matrix with rows index
alpha = np.ones((N,N)) * np.sqrt(2./N) # 1/sqrt(2/N)
alpha[0,:] = np.sqrt(1./N) # alpha(u,x)
A = alpha * np.cos((2*x+1)*u*np.pi / (2.*N)) # Cn(u,x)
return A
In [2]:
testing = (__name__ == "__main__")
if testing:
! jupyter nbconvert --to python dctmatrix.ipynb
import numpy as np
import sys,os
ia898path = os.path.abspath('../../')
if ia898path not in sys.path:
sys.path.append(ia898path)
import ia898.src as ia
In [3]:
if testing:
np.set_printoptions(suppress=True, precision=4)
A = ia.dctmatrix(4)
print('Visualiza matriz DCT 4x4:\n',A)
B = np.dot(A,np.transpose(A))
print("\nVisualiza propriedade A*A'= I:\n", B)
In [4]:
if testing:
%matplotlib inline
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import sys,os
ia898path = os.path.abspath('/home/lotufo')
if ia898path not in sys.path:
sys.path.append(ia898path)
import ia898.src as ia
A = ia.dctmatrix(128)
ia.adshow(ia.normalize(A,[0,255]),'DCT 128x128')
In [ ]:
In [ ]: