lenspack.image.transforms module

lenspack.image.transforms.starlet2d(image, nscales=5)[source]

Compute the multiscale 2D starlet transform of an image.

Parameters
  • image (array_like (2D)) – Input image.

  • nscales (int) – Number of wavelet scales to compute. Should not exceed log2(N), where N is the smaller of the two input dimensions.

Returns

Wavelet coefficients. An input image of shape (N, M) and nscales equal to n will produce an output of shape (n + 1, N, M). The first n maps are wavelet coefficients, while the final map is the coarse scale map.

Return type

3D numpy array

Notes

This function produces the same output as the mr_transform binary of the Sparse2D C++ code package (see References) to high precision.

References

  • Starck, Murtagh, Fadili, ‘Sparse Image and Signal Processing: Wavelets and Related Geometric Multiscale Analysis’, Cambridge University Press, Cambridge (GB), 2016.

  • https://github.com/cosmostat/sparse2d

Examples

>>> # Transform a Gaussian random field of standard deviation 10.
>>> img = 10 * np.random.randn(64, 64)
>>> wt = starlet2d(img, 5)
>>> wt.shape
(6, 64, 64)
>>> # Reconstruction
>>> rec = np.sum(wt, axis=0)
>>> rec.shape == img.shape
True
>>> np.sum(np.abs(rec - img))
2.4814638191483773e-12
lenspack.image.transforms.dct2d(image, norm='ortho')[source]

Compute the discrete cosine transform (type 2) of an image.

Parameters
  • image (array_like, 2D) – Input image.

  • norm ({None, 'ortho', 'sparse2d'}, optional) – Normalization option. See scipy.fftpack.dct documentation (Type II) for a description of the None and ‘ortho’ options. The ‘sparse2d’ option is available to match the output from the im_dct Sparse2D binary, which involves an additional scaling of the zero-frequency elements. Default is ‘ortho’.

Returns

Type 2 DCT.

Return type

2D numpy array

Notes

Using no normalization (i.e. norm=None) will not automatically recover the original image after performing the inverse transformation. Each transform brings an overall scaling factor of 2N.

See also

idct2d

Inverse 2D DCT.

Examples

lenspack.image.transforms.idct2d(image, norm='ortho')[source]

Compute the inverse discrete cosine transform (type 2) of an image.

Parameters
  • image (array_like (2D)) – Input image.

  • norm ({None, 'ortho', 'sparse2d'}, optional) – Normalization option. Default is ‘ortho’.

Returns

Inverse type 2 DCT.

Return type

2D numpy array

See also

dct2d

Forward 2D DCT.

Examples

lenspack.image.transforms.blockdct2d(image, norm='ortho', blocksize=None, overlap=False)[source]

Compute a block (local) discrete cosine transform of an image.

This is an extension of dct2d to perform the transform on sub-blocks of the image.

Parameters
  • image (array_like, 2D) – Input image.

  • norm ({None, 'ortho', 'sparse2d'}, optional) – Normalization option. See scipy.fftpack.dct documentation (Type II) for a description of the None and ‘ortho’ options. The ‘sparse2d’ option is available to match the output from the im_dct Sparse2D binary, which involves an additional scaling of the zero-frequency elements. Default is ‘ortho’.

  • blocksize (int, optional) – Size of sub-blocks for a local DCT.

  • overlap (bool, optional) – Whether to overlap sub-blocks.

Returns

Local type 2 DCT.

Return type

2D numpy array

See also

iblockdct2d

Inverse local 2D DCT.

Examples

Todo

This needs MORE TESTING before deployment !

lenspack.image.transforms.iblockdct2d(image, norm='ortho', blocksize=None, overlap=False)[source]

Compute the inverse block (local) discrete cosine transform of an image.

This is an extension of idct2d to perform the transform on sub-blocks of the image.

Parameters
  • image (array_like, 2D) – Input image.

  • norm ({None, 'ortho', 'sparse2d'}, optional) – Normalization option. See scipy.fftpack.dct documentation (Type II) for a description of the None and ‘ortho’ options. The ‘sparse2d’ option is available to match the output from the im_dct Sparse2D binary, which involves an additional scaling of the zero-frequency elements. Default is ‘ortho’.

  • blocksize (int, optional) – Size of sub-blocks for a local inverse DCT.

  • overlap (bool, optional) – Whether to overlap sub-blocks.

Returns

Local type 2 inverse DCT.

Return type

2D numpy array

Examples

Todo

This needs MORE TESTING before deployment !

lenspack.image.transforms.mr_transform(image, nscales=4, type=2, verbose=False)[source]

Compute the multi-resolution wavelet transform of an image.

Parameters
  • image (array_like, 2D) – Input image.

  • nscales (int, optional) – Number of wavelet scales to compute. Default is 4.

  • type (int, optional) – Type of the multiresolution transform. See the original mr_transform documentation for details. Default is 2, which corresponds to the ‘bspline wavelet transform: a trous algorithm’, i.e. the starlet.

  • verbose (bool, optional) – If True, print details of the temporary file I/O process.

Returns

Result of the wavelet transform.

Return type

3D numpy array

Notes

This function is a wrapper for the mr_transform C++ binary of the Sparse2D code package (see References). The astropy package is necessary to write out image as a temporary fits file on which mr_transform can act.

References

  • Starck, Murtagh, Fadili, ‘Sparse Image and Signal Processing: Wavelets and Related Geometric Multiscale Analysis’, Cambridge University Press, Cambridge (GB), 2016.

  • https://github.com/cosmostat/sparse2d

Examples