Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

dctmtx

Discrete Cosine Transform Matrix


Description

Compute the discrete cosine transform matrix.

Usage

dctmtx(n)

Arguments

n

Size of DCT matrix, specified as a positive integer.

Details

A DCT transformation matrix is useful for doing things like JPEG image compression, in which an 8x8 DCT matrix is applied to non-overlapping blocks throughout an image and only a sub-block on the top left of each block is kept. During restoration, the remainder of the block is filled with zeros and the inverse transform is applied to the block.

The two-dimensional DCT of A can be computed as D %*% A %*% t(D). This computation is sometimes faster than using dct2, especially if you are computing a large number of small DCTs, because D needs to be determined only once. For example, in JPEG compression, the DCT of each 8-by-8 block is computed. To perform this computation, use dctmtx to determine D of input image A, and then calculate each DCT using D %*% A %*% t(D) (where A is each 8-by-8 block). This is faster than calling dct2 for each individual block.

Value

Discrete cosine transform, returned as a vector or matrix.

Author(s)

Paul Kienzle, pkienzle@users.sf.net.
Conversion to R by Geert van Boxtel, G.J.M.vanBoxtel@gmail.com.

See Also

Examples

D <- dctmtx(8)

#if (requireNamespace("imager", quietly = TRUE)) {
#   boats <- imager::boats
#   A <- imager::grayscale(boats)[1:256, 65:320, 1, 1]  # make it 256*256
#   plot(imager::as.cimg(A), axes = FALSE, main = "Boats from imager package")
#   D <- dctmtx(nrow(A))
#   ctrans <- D %*% A %*% t(D)
#   ctrans2 <- dct2(A)
#   all.equal(ctrans, ctrans2)
# }

gsignal

Signal Processing

v0.3-1
GPL-3
Authors
Geert van Boxtel [aut, cre] (Maintainer), Tom Short [aut] (Author of 'signal' package), Paul Kienzle [aut] (Majority of the original sources), Ben Abbott [ctb], Juan Aguado [ctb], Muthiah Annamalai [ctb], Leonardo Araujo [ctb], William Asquith [ctb], David Bateman [ctb], David Billinghurst [ctb], Juan Pablo Carbajal [ctb], André Carezia [ctb], Vincent Cautaerts [ctb], Eric Chassande-Mottin [ctb], Luca Citi [ctb], Dave Cogdell [ctb], Carlo de Falco [ctb], Carne Draug [ctb], Pascal Dupuis [ctb], John W. Eaton [ctb], R.G.H Eschauzier [ctb], Andrew Fitting [ctb], Alan J. Greenberger [ctb], Mike Gross [ctb], Daniel Gunyan [ctb], Kai Habel [ctb], Kurt Hornik [ctb], Jake Janovetz [ctb], Alexander Klein [ctb], Peter V. Lanspeary [ctb], Bill Lash [ctb], Friedrich Leissh [ctb], Laurent S. Mazet [ctb], Mike Miller [ctb], Petr Mikulik [ctb], Paolo Neis [ctb], Georgios Ouzounis [ctb], Sylvain Pelissier [ctb], Francesco Potortì [ctb], Charles Praplan [ctb], Lukas F. Reichlin [ctb], Tony Richardson [ctb], Asbjorn Sabo [ctb], Thomas Sailer [ctb], Rolf Schirmacher [ctb], Rolf Schirmacher [ctb], Ivan Selesnick [ctb], Julius O. Smith III [ctb], Peter L. Soendergaard [ctb], Quentin Spencer [ctb], Doug Stewart [ctb], P. Sudeepam [ctb], Stefan van der Walt [ctb], Andreas Weber [ctb], P. Sudeepam [ctb], Andreas Weingessel [ctb]
Initial release
2021-05-02

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.