magni.imaging.dictionaries._fastops module

Module providing functionality related to linear transformations.

Routine listings

dct2(x, mn_tuple, overcomplete_mn_tuple=None)
2D discrete cosine transform.
idct2(x, mn_tuple, overcomplete_mn_tuple=None)
2D inverse discrete cosine transform.
dft2(x, mn_tuple, overcomplete_mn_tuple=None)
2D discrete Fourier transform.
idft2(x, mn_tuple, overcomplete_mn_tuple=None)
2D inverse discrete Fourier transform.
magni.imaging.dictionaries._fastops.dct2(x, mn_tuple, overcomplete_mn_tuple=None)[source]

Apply the 2D Discrete Cosine Transform (DCT).

x is assumed to be the column vector resulting from stacking the columns of the associated matrix which the transform is to be taken on.

Parameters:
  • x (ndarray) – The m*n x 1 vector representing the associated column stacked matrix.
  • mn_tuple (tuple of int) – (m, n) - m number of rows in the matrix represented by x; n number of columns in the matrix.
  • overcomplete_mn_tuple (tuple of int, optional) – (mo, no) - mo number of rows in the matrix represented by the function’s output; no number of columns in the matrix.
Returns:

alpha (ndarray) – When overcomplete_mn_tuple is omitted: an m*n x 1 vector of coefficients scaled such that x = idct2(dct2(x)). When overcomplete_mn_tuple is supplied: an mo*no x 1 vector of coefficients scaled such that x = idct2(dct2(x)).

See also

scipy.fftpack.dct()
1D DCT

Notes

The overcomplete transform feature invoked by supplying overcomplete_mn_tuple is only available for SciPy >= 0.16.1.

The 2D DCT uses the seperability property of the 1D DCT. http://stackoverflow.com/questions/14325795/scipys-fftpack-dct-and-idct Including the reshape operation, the full transform is: dct(dct(x.reshape(n, m).T).T).T.T.reshape(m * n, 1)

magni.imaging.dictionaries._fastops.idct2(x, mn_tuple, overcomplete_mn_tuple=None)[source]

Apply the 2D Inverse Discrete Cosine Transform (iDCT).

x is assumed to be the column vector resulting from stacking the columns of the associated matrix which the transform is to be taken on.

Parameters:
  • x (ndarray) – The vector representing the associated column-stacked matrix. When overcomplete_mn_tuple is omitted: the shape must be m*n x 1. When overcomplete_mn_tuple is supplied: the shape must be mo*no x 1.
  • mn_tuple (tuple of int) – (m, n) - m number of rows in the associated matrix, n number of columns in the associated matrix. When overcomplete_mn_tuple is supplied, this is the shape of the function’s output.
  • overcomplete_mn_tuple (tuple of int, optional) – (mo, no) - mo number of rows in the associated matrix, no number of columns in the associated matrix. When supplied, this is the shape of the function’s input.
Returns:

ndarray – An m*n x 1 vector of coefficients scaled such that x = dct2(idct2(x)).

See also

scipy.fftpack.idct()
1D inverse DCT

Notes

The overcomplete transform feature invoked by supplying overcomplete_mn_tuple is only available for SciPy >= 0.16.1.

magni.imaging.dictionaries._fastops.dft2(x, mn_tuple, overcomplete_mn_tuple=None)[source]

Apply the 2D Discrete Fourier Transform (DFT).

x is assumed to be the column vector resulting from stacking the columns of the associated matrix which the transform is to be taken on.

Parameters:
  • x (ndarray) – The m*n x 1 vector representing the associated column stacked matrix.
  • mn_tuple (tuple of int) – (m, n) - m number of rows in the matrix represented by x; n number of columns in the matrix.
  • overcomplete_mn_tuple (tuple of int, optional) – (mo, no) - mo number of rows in the matrix represented by the function’s output; no number of columns in the matrix.
Returns:

ndarray – When overcomplete_mn_tuple is omitted: an m*n x 1 vector of coefficients scaled such that x = idft2(dft2(x)). When overcomplete_mn_tuple is supplied: an mo*no x 1 vector of coefficients scaled such that x = idft2(dft2(x)).

See also

numpy.fft.fft2()
The underlying 2D FFT used to compute the 2D DFT.

Notes

This is a normalised DFT, i.e. a normalisation constant of \(\sqrt{m * n}\) is used.

magni.imaging.dictionaries._fastops.idft2(x, mn_tuple, overcomplete_mn_tuple=None)[source]

Apply the 2D Inverse Discrete Fourier Transform (iDFT).

x is assumed to be the column vector resulting from stacking the columns of the associated matrix which the transform is to be taken on.

Parameters:
  • x (ndarray) – The m*n x 1 vector representing the associated column stacked matrix.
  • mn_tuple (tuple of int) – (m, n) - m number of rows in the associated matrix, n number of columns in the associated matrix. When overcomplete_mn_tuple is supplied, this is the shape of the function’s output.
  • overcomplete_mn_tuple (tuple of int, optional) – (mo, no) - mo number of rows in the associated matrix, no number of columns in the associated matrix. When supplied, this is the shape of the function’s input.
Returns:

ndarray – An m*n x 1 vector of coefficients scaled such that x = dft2(idft2(x)).

See also

numpy.fft.ifft2()
The underlying 2D iFFT used to compute the 2D iDFT.

Notes

This is a normalised iDFT, i.e. a normalisation constant of \(\sqrt{m * n}\) is used.

magni.imaging.dictionaries._fastops._validate_transform_fwd(x, mn_tuple, overcomplete_mn_tuple=None)[source]

Validate a 2D transform.

Parameters:
  • x (ndarray) – The m*n x 1 vector representing the associated column stacked matrix.
  • mn_tuple (tuple of int) – (m, n) - m number of rows in the matrix represented by x; n number of columns in the matrix.
  • overcomplete_mn_tuple (tuple of int, optional) – (mo, no) - mo number of rows in the matrix represented by the function’s output; no number of columns in the matrix.
magni.imaging.dictionaries._fastops._validate_transform_bwd(x, mn_tuple, overcomplete_mn_tuple=None)[source]

Validate a 2D transform.

Parameters:
  • x (ndarray) – The m*n x 1 vector representing the associated column stacked matrix.
  • mn_tuple (tuple of int) – (m, n) - m number of rows in the associated matrix, n number of columns in the associated matrix.
  • overcomplete_mn_tuple (tuple of int, optional) – (mo, no) - mo number of rows in the associated matrix, no number of columns in the associated matrix.