zh217 / torch-dct

DCT (discrete cosine transform) functions for pytorch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

not equal with scipy.fftpack.dct

machengcheng2016 opened this issue · comments

The function dct is not equal with scipy.fftpack.dct.
I assume that scipy.fftpack.dct is correct, since scipy.fftpack.dct is equal with matlab's dct.

commented

The function dct is not equal with scipy.fftpack.dct.
I assume that scipy.fftpack.dct is correct, since scipy.fftpack.dct is equal with matlab's dct.

So do you find any function to implement scipy.fftpack.dct in python or in pytorch?

The function dct is not equal with scipy.fftpack.dct.
I assume that scipy.fftpack.dct is correct, since scipy.fftpack.dct is equal with matlab's dct.

So do you find any function to implement scipy.fftpack.dct in python or in pytorch?

Sorry for the late.
Seems it's been a long time that I found this bug... I installed the 'torch-dct' and tried to reproduce this bug just now (Env: python==3.5, scipy==1.3.1). I got four awkward conclusions as follows:

  1. The 1D-DCT result of torch_dct is same with that of scipy.fftpack.dct, as long as the norm option is samely set.
    Specifically, the result of torch_dct.dct(torch.from_numpy(numpy_1d_array).float(), norm='ortho') and that of scipy.fftpack.dct(numpy_1d_array, norm='ortho') are the same.
    The result of torch_dct.dct(torch.from_numpy(numpy_1d_array).float()) and that of scipy.fftpack.dct(numpy_1d_array) are the same, too.

  2. The 2D-DCT result of torch_dct is same with that of scipy.fftpack.dct, as long as the norm option is samely set.
    The way of computing 2D-DCT with scipy.fftpack.dct is like scipy.fftpack.dct(scipy.fftpack.dct(gray_image_numpy.T).T), as suggested in https://stackoverflow.com/a/15981676

  1. The 1D-DCT result of scipy.fftpack.dct and that of Matlab2018A are different, unless I change the norm option from the default None to ortho.
    For example, in Python
    scipy.fftpack.dct(np.array([1., 1., 1.])) = array([6., 0., 0.])
    scipy.fftpack.dct(np.array([1., 1., 1.]), norm='ortho') = array([1.73205081, 0., 0.])
    torch_dct.dct(torch.FloatTensor([1., 1., 1.])) = tensor([6., 0., 0.])
    torch_dct.dct(torch.FloatTensor([1., 1., 1.]), norm='ortho') = tensor([1.7321, 0.0000, 0.0000])
    in Matlab2018A
    dct([1,1,1])=[1.7321, 0, 0];

  2. The 2D-DCT result of scipy.fftpack.dct and that of Matlab2018A are different, unless I change the norm option from the default None to ortho.

So, I think there are no bugs in torch_dct. Maybe we should check whether the norm option is correctly set before we do experiments.

@machengcheng2016 Hi, for point number 2 2D-DCT, could you share the complete code of how you computing DCT in PyTorch and Scipy? I set the norm as "ortho" but the results are not the same.