.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/plot_single_curvelet.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_plot_single_curvelet.py: 1. Visualize a Single Curvelet ============================== This example shows a single curvelet coefficient in spatial and frequency domains. .. GENERATED FROM PYTHON SOURCE LINES 9-16 .. code-block:: default import matplotlib.pyplot as plt import numpy as np from matplotlib.ticker import MultipleLocator from curvelops import FDCT2D from curvelops.plot import create_colorbar .. GENERATED FROM PYTHON SOURCE LINES 17-19 Setup ===== .. GENERATED FROM PYTHON SOURCE LINES 19-24 .. code-block:: default m = 512 n = 512 x = np.zeros((m, n)) DCT = FDCT2D(x.shape) .. GENERATED FROM PYTHON SOURCE LINES 25-27 Curvelet Domain =============== .. GENERATED FROM PYTHON SOURCE LINES 29-35 .. code-block:: default y = DCT * x # Convert to a curvelet struct indexed by # [scale, wedge (angle), x, y] y_reshape = DCT.struct(y) .. GENERATED FROM PYTHON SOURCE LINES 36-38 Select single curvelet ====================== .. GENERATED FROM PYTHON SOURCE LINES 38-47 .. code-block:: default s = 4 w = 0 a, b = y_reshape[s][w].shape normalization = np.sqrt(y_reshape[s][w].size) y_reshape[s][w][a // 2, b // 2] = 1 * normalization y_reshape[s][w + len(y_reshape[s]) // 2][a // 2, b // 2] = -1j * normalization y = DCT.vect(y_reshape) .. GENERATED FROM PYTHON SOURCE LINES 48-50 Perform adjoint transform and reshape ===================================== .. GENERATED FROM PYTHON SOURCE LINES 50-52 .. code-block:: default x = DCT.H @ y .. GENERATED FROM PYTHON SOURCE LINES 53-55 F-K domain ========== .. GENERATED FROM PYTHON SOURCE LINES 55-57 .. code-block:: default x_fk = np.fft.fftshift(np.fft.fft2(np.fft.ifftshift(x), norm="ortho")) .. GENERATED FROM PYTHON SOURCE LINES 58-60 Visualize ========= .. GENERATED FROM PYTHON SOURCE LINES 60-92 .. code-block:: default vmin, vmax = 0.8 * np.array([-1, 1]) * np.abs(np.max(x)) fig, ax = plt.subplots(2, 2, figsize=(8, 8), sharex="row", sharey="row") im = ax[0, 0].imshow(x.real.T, cmap="gray", vmin=vmin, vmax=vmax) create_colorbar(im, ax[0, 0]) im = ax[0, 1].imshow(x.imag.T, cmap="gray", vmin=vmin, vmax=vmax) create_colorbar(im, ax[0, 1]) im = ax[1, 0].imshow(np.abs(x_fk).T, cmap="turbo", vmin=0) create_colorbar(im, ax[1, 0]) mask = np.abs(x_fk) > 0.01 * np.abs(x_fk).max() im = ax[1, 1].imshow( (mask * np.angle(x_fk, deg=True)).T, cmap="twilight_shifted", vmin=-180, vmax=180, ) cax, cb = create_colorbar(im, ax[1, 1]) cax.get_yaxis().set_major_locator(MultipleLocator(45)) ax[0, 0].set( xlim=(m // 2 - 50, m // 2 + 50), ylim=(n // 2 - 50, n // 2 + 50), title="Space domain (Real) magnified", ) ax[0, 1].set(title="Space domain (Imag) magnified") ax[1, 0].set(title="Frequency domain (Abs)") ax[1, 1].set(title="Frequency domain (Phase)") fig.tight_layout() .. image-sg:: /gallery/images/sphx_glr_plot_single_curvelet_001.png :alt: Space domain (Real) magnified, Space domain (Imag) magnified, Frequency domain (Abs), Frequency domain (Phase) :srcset: /gallery/images/sphx_glr_plot_single_curvelet_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 1.330 seconds) .. _sphx_glr_download_gallery_plot_single_curvelet.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_single_curvelet.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_single_curvelet.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_