.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_advanced_image_processing_auto_examples_plot_propagation.py: Opening, erosion, and propagation ================================== This example shows simple operations of mathematical morphology. .. image:: /advanced/image_processing/auto_examples/images/sphx_glr_plot_propagation_001.png :class: sphx-glr-single-img .. code-block:: python import numpy as np from scipy import ndimage import matplotlib.pyplot as plt square = np.zeros((32, 32)) square[10:-10, 10:-10] = 1 np.random.seed(2) x, y = (32*np.random.random((2, 20))).astype(np.int) square[x, y] = 1 open_square = ndimage.binary_opening(square) eroded_square = ndimage.binary_erosion(square) reconstruction = ndimage.binary_propagation(eroded_square, mask=square) plt.figure(figsize=(9.5, 3)) plt.subplot(131) plt.imshow(square, cmap=plt.cm.gray, interpolation='nearest') plt.axis('off') plt.subplot(132) plt.imshow(open_square, cmap=plt.cm.gray, interpolation='nearest') plt.axis('off') plt.subplot(133) plt.imshow(reconstruction, cmap=plt.cm.gray, interpolation='nearest') plt.axis('off') plt.subplots_adjust(wspace=0, hspace=0.02, top=0.99, bottom=0.01, left=0.01, right=0.99) plt.show() **Total running time of the script:** ( 0 minutes 0.030 seconds) .. _sphx_glr_download_advanced_image_processing_auto_examples_plot_propagation.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_propagation.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_propagation.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_