.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "advanced/image_processing/auto_examples/plot_block_mean.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end <sphx_glr_download_advanced_image_processing_auto_examples_plot_block_mean.py>` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_advanced_image_processing_auto_examples_plot_block_mean.py: Plot the block mean of an image ================================ An example showing how to use broad-casting to plot the mean of blocks of an image. .. GENERATED FROM PYTHON SOURCE LINES 8-26 .. image-sg:: /advanced/image_processing/auto_examples/images/sphx_glr_plot_block_mean_001.png :alt: plot block mean :srcset: /advanced/image_processing/auto_examples/images/sphx_glr_plot_block_mean_001.png :class: sphx-glr-single-img .. code-block:: Python import numpy as np import scipy as sp import matplotlib.pyplot as plt f = sp.datasets.face(gray=True) sx, sy = f.shape X, Y = np.ogrid[0:sx, 0:sy] regions = sy // 6 * (X // 4) + Y // 6 block_mean = sp.ndimage.mean(f, labels=regions, index=np.arange(1, regions.max() + 1)) block_mean.shape = (sx // 4, sy // 6) plt.figure(figsize=(5, 5)) plt.imshow(block_mean, cmap="gray") plt.axis("off") plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.196 seconds) .. _sphx_glr_download_advanced_image_processing_auto_examples_plot_block_mean.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_block_mean.ipynb <plot_block_mean.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_block_mean.py <plot_block_mean.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_block_mean.zip <plot_block_mean.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_