使用Python的Scipy DCT-II进行2D或ND DCT

mac*_*sme 6 python dct scipy

我想使用scipy的DCT-II,因为它已经编码并且速度很快.看一下这个文档,它似乎是一维实现.是否可以以这种方式使用它作为3D实现?我不确定数学.2D和3D实现相当于在计算中使用不同尺寸乘以1D的2或3倍?

mac*_*sme 6

基本上,以下是诀窍:

import numpy as np
from scipy.fftpack import dct, idct

# Lets create a 3D array and fill it with some values
a = numpy.random.rand(3,3,3)

f,x,y = a.shape
b = np.zeros((f,x,y))

b = dct(dct(dct(a).transpose(0,2,1)).transpose(1,2,0)).transpose(1,2,0).transpose(0,2,1)
Run Code Online (Sandbox Code Playgroud)