Need help with torch-dct?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

zh217
160 Stars 27 Forks MIT License 27 Commits 5 Opened issues

Description

DCT (discrete cosine transform) functions for pytorch

Services available

!
?

Need anything else?

Contributors list

# 298,255
Java
Shell
Python
fft
17 commits
# 216,795
pytorch
Python
convolu...
Shell
2 commits
# 160,443
instanc...
Python
image-a...
pytorch
1 commit

DCT (Discrete Cosine Transform) for pytorch

Build Status codecov PyPI version PyPI version PyPI status GitHub license

This library implements DCT in terms of the built-in FFT operations in pytorch so that back propagation works through it, on both CPU and GPU. For more information on DCT and the algorithms used here, see Wikipedia and the paper by J. Makhoul. This StackExchange article might also be helpful.

The following are currently implemented:

  • 1-D DCT-I and its inverse (which is a scaled DCT-I)
  • 1-D DCT-II and its inverse (which is a scaled DCT-III)
  • 2-D DCT-II and its inverse (which is a scaled DCT-III)
  • 3-D DCT-II and its inverse (which is a scaled DCT-III)

Install

pip install torch-dct

Requires

torch>=0.4.1
(lower versions are probably OK but I haven't tested them).

You can run test by getting the source and run

pytest
. To run the test you also need
scipy
installed.

Usage

import torch
import torch_dct as dct

x = torch.randn(200) X = dct.dct(x) # DCT-II done through the last dimension y = dct.idct(X) # scaled DCT-III done through the last dimension assert (torch.abs(x - y)).sum() < 1e-10 # x == y within numerical tolerance

dct.dct1
and
dct.idct1
are for DCT-I and its inverse. The usage is the same.

Just replace

dct
and
idct
by
dct_2d
,
dct_3d
,
idct_2d
,
idct_3d
, etc to get the multidimensional versions.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.