[GO] Calculate 2D IDCT ~ Python

Introduction

Calculate 2D IDCT using Python.

code

test.py


from numpy import *
from scipy.fftpack import dct, idct

set_printoptions(linewidth=200, precision=1, suppress=True)

def dct2(a):
    return dct( dct( a, axis=0, norm='ortho' ), axis=1, norm='ortho' )

def idct2(a):
    return idct( idct( a, axis=0 , norm='ortho'), axis=1 , norm='ortho')

a = array(
  [
    ( 568,     0,     0,    -4,    -4,     0,     4,     0 ),
    ( -27,     9,    -4,    -4,     0,    -5,     5,    -5 ),
    ( -49,    -4,     4,     4,     0,     0,     0,     0 ),
    ( -12,    -4,     0,     0,     5,     0,     0,     0 ),
    ( -14,    -5,     0,     0,     0,     0,     0,     0 ),
    (  -5,     0,     0,     0,     0,     0,     0,     0 ),
    (  -5,     0,     0,     0,     0,     0,     0,     0 ),
    (   0,     0,     0,     0,     0,     0,     0,     1 ),
  ]
);

print("a=")
print(a)
print("idct2(a)=")
print(idct2(a))
print("dct2(idct2(a))=")
print(dct2(idct2(a)))

I will do it.

> python --version
Python 3.4.3
> python .\test.py
a=
[[568   0   0  -4  -4   0   4   0]
 [-27   9  -4  -4   0  -5   5  -5]
 [-49  -4   4   4   0   0   0   0]
 [-12  -4   0   0   5   0   0   0]
 [-14  -5   0   0   0   0   0   0]
 [ -5   0   0   0   0   0   0   0]
 [ -5   0   0   0   0   0   0   0]
 [  0   0   0   0   0   0   0   1]]
idct2(a)=
[[ 52.9  53.6  54.8  54.   53.   56.3  50.3  56.9]
 [ 67.9  70.5  71.4  68.1  65.2  68.6  62.4  66.4]
 [ 74.4  78.4  80.5  75.   72.   74.5  70.   71.2]
 [ 74.7  78.5  81.3  78.3  75.3  77.5  75.1  76.2]
 [ 75.7  76.4  80.1  78.9  78.2  77.5  78.4  79.5]
 [ 75.6  74.   76.1  76.4  76.   75.   77.3  77.4]
 [ 73.3  71.   72.3  70.7  72.5  72.7  77.1  73.9]
 [ 67.   65.6  66.1  63.6  66.5  69.6  75.   69.4]]
dct2(idct2(a))=
[[ 568.   -0.   -0.   -4.   -4.   -0.    4.   -0.]
 [ -27.    9.   -4.   -4.    0.   -5.    5.   -5.]
 [ -49.   -4.    4.    4.   -0.    0.    0.   -0.]
 [ -12.   -4.   -0.   -0.    5.    0.    0.   -0.]
 [ -14.   -5.   -0.    0.    0.    0.   -0.   -0.]
 [  -5.   -0.    0.    0.   -0.    0.    0.   -0.]
 [  -5.    0.    0.    0.   -0.   -0.    0.   -0.]
 [   0.    0.    0.   -0.    0.   -0.    0.    1.]]

Recommended Posts

Calculate 2D IDCT ~ Python
[Python] Binary Acing 2020D
Create 3d gif with python3
Python: 3D array image (numpy.array)
[Python] Dynamic programming TDPC D
python> Handling of 2D arrays
Solve ABC175 D in Python
AtCoder ABC 182 Python (A ~ D)
Python 2D array trap [Copy array]
3D skeleton structure analysis with Python
Python
Solve ABC166 A ~ D with Python
Calculate free-space path loss in Python
Try to calculate Trace in Python
Calculate the previous month in Python
How to calculate date with python
I'm addicted to Python 2D lists
[Python scipy] Upscale / downscale 2D data
Calculate and display standard weight with python
[Python] How to convert a 2D list to a 1D list
ABC 157 D --Solve Friend Suggestions in Python!
2D FEM stress analysis program with Python
Let Python calculate Euler-Lagrange's equation of motion
Python> link> 2D array initialization and assignment
Example of 3D skeleton analysis by Python
Don't use \ d in Python 3 regular expressions!
Solve AtCoder ABC168 with python (A ~ D)
AtCoder Beginner Contest: D Question Answers Python
Solve ABC165 A, B, D in Python
[Python] How to calculate MAE and RMSE
[Python] I tried to calculate TF-IDF steadily