pystem.tools.dct module

This module defines some functions related to DCT decomposition including:

  • direct and inverse normalized 2D DCT transform,

  • direct and inverse band-by-band DCT transform for multi-band data.

2D transformations

pystem.tools.dct.dct2d(a)

Computes the 2D Normalized DCT-II.

Parameters

X ((m, n) numpy array) – 2D image.

Returns

DCT coefficient matrix.

Return type

(m, n) numpy array

Example

>>> from pystem.tools.dct import dct2d
>>> import scipy.misc
>>> face = scipy.misc.face()
>>> A = dct2d(face.sum(2))
pystem.tools.dct.idct2d(a)

Computes the 2D Normalized Inverse DCT-II.

Parameters

A ((m, n) numpy array) – DCT coefficient matrix

Returns

2D image.

Return type

(m, n) numpy array

Example

>>> from pystem.tools.dct import dct2d, idct2d
>>> import scipy.misc
>>> face = scipy.misc.face()
>>> A = dct2d(face.sum(2))
>>> X = idct2d(A)

Band-by-band transformations

pystem.tools.dct.dct2d_bb(x, size=None)

Computes the band-by-band 2D Normalized DCT-II

If the input X is a 3D data cube, the 2D dct will be computed for each 2D images staked along the 2nd axis.

Parameters
  • X ((l, m*n) or (m, n, l) numpy array) – 2D or 3D multi-band data. If the data has 3 dimensions, the last axis is for spetra. If the data is 2D, the first axis is for spectra.

  • size (optional, (m, n) tuple) – This is the spatial size. This parameter is required only if input data are 2D.

Returns

DCT coefficient matrix.

Return type

(l, m*n) or (m, n, l) numpy array

Example

>>> from pystem.tools.dct import dct2d_bb
>>> import scipy.misc
>>> face = scipy.misc.face()
>>> A = dct2d_bb(face)
pystem.tools.dct.idct2d_bb(a, size=None)

Computes the band-by-band inverse 2D Normalized DCT-II

If the input a is a 3D data cube, the 2D dct will be computed for each 2D images staked along the 2nd axis.

Parameters
  • A ((l, m*n) or (m, n, l) numpy array) – 2D or 3D multi-band data DCT decomposition. If the data has 3 dimensions, the last axis is for spetra. If the data is 2D, the first axis is for spectra.

  • size (optional, (m, n) tuple) – This is the spatial size. This parameter is required only if input data are 2D.

Returns

The image matrix.

Return type

(l, m*n) or (m, n, l) numpy array

Example

>>> from pystem.tools.dct import dct2d_bb, idct2d_bb
>>> import scipy.misc
>>> import numpy.testing as npt
>>> face = scipy.misc.face()
>>> A = dct2d_bb(face)
>>> X = idct2d_bb(A)
>>> npt.assert_allclose(X, face, atol=1e-12)