.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/transform/plot_pyramid.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. or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_transform_plot_pyramid.py: ==================== Build image pyramids ==================== The ``pyramid_gaussian`` function takes an image and yields successive images shrunk by a constant scale factor. Image pyramids are often used, e.g., to implement algorithms for denoising, texture discrimination, and scale-invariant detection. .. GENERATED FROM PYTHON SOURCE LINES 12-24 .. code-block:: Python import numpy as np import matplotlib.pyplot as plt from skimage import data from skimage.transform import pyramid_gaussian image = data.astronaut() rows, cols, dim = image.shape pyramid = tuple(pyramid_gaussian(image, downscale=2, channel_axis=-1)) .. GENERATED FROM PYTHON SOURCE LINES 25-38 Generate a composite image for visualization ============================================ For visualization, we generate a composite image with the same number of rows as the source image but with ``cols + pyramid[1].shape[1]`` columns. We then have space to stack all of the dowsampled images to the right of the original. Note: The sum of the number of rows in all dowsampled images in the pyramid may sometimes exceed the original image size in cases when image.shape[0] is not a power of two. We expand the number of rows in the composite slightly as necessary to account for this. Expansion beyond the number of rows in the original will also be necessary to cover cases where downscale < 2. .. GENERATED FROM PYTHON SOURCE LINES 38-57 .. code-block:: Python # determine the total number of rows and columns for the composite composite_rows = max(rows, sum(p.shape[0] for p in pyramid[1:])) composite_cols = cols + pyramid[1].shape[1] composite_image = np.zeros((composite_rows, composite_cols, 3), dtype=np.double) # store the original to the left composite_image[:rows, :cols, :] = pyramid[0] # stack all downsampled images in a column to the right of the original i_row = 0 for p in pyramid[1:]: n_rows, n_cols = p.shape[:2] composite_image[i_row : i_row + n_rows, cols : cols + n_cols] = p i_row += n_rows fig, ax = plt.subplots() ax.imshow(composite_image) plt.show() .. image-sg:: /auto_examples/transform/images/sphx_glr_plot_pyramid_001.png :alt: plot pyramid :srcset: /auto_examples/transform/images/sphx_glr_plot_pyramid_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.341 seconds) .. _sphx_glr_download_auto_examples_transform_plot_pyramid.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/scikit-image/scikit-image/v0.24.0?filepath=notebooks/auto_examples/transform/plot_pyramid.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_pyramid.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_pyramid.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_