Giter VIP home page Giter VIP logo

torch-dct's Introduction

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.

torch-dct's People

Contributors

zh217 avatar gngdb avatar travishsu avatar adam-dziedzic avatar professorsearcher avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.