dct-2d-fromdefinition
v1.6.0
Published
Implementation of the Discrete Cosine Transform for 2D inputs, and its inverse, from its definition equation.
Readme
This Node module is an implementation of the two-dimensional Discrete Cosine Transform (2D-DCT), and its inverse, from its very definition. It is intended for educational and research purposes. You should use this module with small inputs only, since calculating the transform from the definition is inefficient.
The equations below show the definition of the 2D-DCT and the conventions supported in this module.
Installation
npm install dct-2d-fromdefinition
Usage
Note that the inputs and outputs are matrices of complex values, so as to support complex signals. If your signal is real, just convert it to complex first, e.g., [[8,9],[7,6]] becomes [[[8,0],[9,0]],[[7,0],[6,0]]].
Forward transform
const dct2ddef = require('dct-2d-fromdefinition');
let signal = [[[1,1],[2,0]],[[4,4],[5,0]]]; // corresponds to the complex signal [[1+j,2],[4+4j,5]]
let transform = dct2ddef.dct(signal, 'orthogonal_unitary');
console.log(transform);
// Gives approx. [[[6,2.5],[-1,2.5]],[[-3,-1.5],[0,-1.5]]]Inverse transform
const dct2ddef = require('dct-2d-fromdefinition');
let transform = [[[6,2.5],[-1,2.5]],[[-3,-1.5],[0,-1.5]]];
let signal = dct2ddef.idct(transform, 'orthogonal_unitary');
console.log(signal);
// Gives approx. [[[1,1],[2,0]],[[4,4],[5,0]]] // corresponds to the complex signal [[1+j,2],[4+4j,5]]Acknowledgements
The project that gave rise to these results received the support of a fellowship from ”la Caixa” Foundation (ID 100010434). The fellowship code is LCF/BQ/DI22/11940036. This work was also supported by FCT through the LASIGE Research Unit (UID/00408/2025).
License
This work is licensed under CC BY 4.0. See LICENSE for more details.
