magni.imaging.dictionaries._matrices module¶
Module providing fast linear operations wrapped in matrix emulators.
Routine listings¶
- get_DCT(shape, overcomplete_shape=None)
- Get the DCT fast operation dictionary for the given image shape.
- get_DFT(shape, overcomplete_shape=None)
- Get the DFT fast operation dictionary for the given image shape.
See also
magni.imaging.dictionaries._fastops
- Fast linear operations.
magni.utils.matrices
- Matrix emulators.
-
magni.imaging.dictionaries._matrices.
get_DCT
(shape, overcomplete_shape=None)[source]¶ Get the DCT fast operation dictionary for the given image shape.
Parameters: - shape (list or tuple) – The shape of the image for which the dictionary is the DCT dictionary.
- overcomplete_shape (list or tuple, optional) – The shape of the (overcomplete) frequency domain for the DCT dictionary. The entries must be greater than or equal to the corresponding entries in shape.
Returns: matrix (magni.utils.matrices.Matrix) – The specified DCT dictionary.
See also
magni.utils.matrices.Matrix()
- The matrix emulator class.
Examples
Create a dummy image:
>>> import numpy as np, magni >>> img = np.random.randn(64, 64) >>> vec = magni.imaging.mat2vec(img)
Perform DCT in the ordinary way:
>>> dct_normal = magni.imaging.dictionaries._fastops.dct2(vec, img.shape)
Perform DCT using the present function:
>>> from magni.imaging.dictionaries import get_DCT >>> matrix = get_DCT(img.shape) >>> dct_matrix = matrix.T.dot(vec)
Check that the two ways produce the same result:
>>> np.allclose(dct_matrix, dct_normal) True
Compute the overcomplete transform (and back again) and check that the resulting image is identical to the original. Notice how this example first ensures that the necessary version of SciPy is available:
>>> from pkg_resources import parse_version >>> from scipy import __version__ as _scipy_version >>> if parse_version(_scipy_version) >= parse_version('0.16.0'): ... matrix = get_DCT(img.shape, img.shape) ... dct_matrix = matrix.T.dot(vec) ... vec_roundtrip = matrix.dot(dct_matrix) ... np.allclose(vec, vec_roundtrip) ... else: ... True True
-
magni.imaging.dictionaries._matrices.
get_DFT
(shape, overcomplete_shape=None)[source]¶ Get the DFT fast operation dictionary for the given image shape.
Parameters: - shape (list or tuple) – The shape of the image for which the dictionary is the DFT dictionary.
- overcomplete_shape (list or tuple, optional) – The shape of the (overcomplete) frequency domain for the DFT dictionary. The entries must be greater than or equal to the corresponding entries in shape.
Returns: matrix (magni.utils.matrices.Matrix) – The specified DFT dictionary.
See also
magni.utils.matrices.Matrix()
- The matrix emulator class.
Examples
Create a dummy image:
>>> import numpy as np, magni >>> img = np.random.randn(64, 64) >>> vec = magni.imaging.mat2vec(img)
Perform DFT in the ordinary way:
>>> dft_normal = magni.imaging.dictionaries._fastops.dft2(vec, img.shape)
Perform DFT using the present function:
>>> from magni.imaging.dictionaries import get_DFT >>> matrix = get_DFT(img.shape) >>> dft_matrix = matrix.conj().T.dot(vec)
Check that the two ways produce the same result:
>>> np.allclose(dft_matrix, dft_normal) True
Compute the overcomplete transform (and back again):
>>> matrix = get_DFT(img.shape, img.shape) >>> dft_matrix = matrix.conj().T.dot(vec) >>> vec_roundtrip = matrix.dot(dft_matrix)
Check that the twice transformed image is identical to the original:
>>> np.allclose(vec, vec_roundtrip) True