.. 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_greyscale_dilation.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_advanced_image_processing_auto_examples_plot_greyscale_dilation.py: Greyscale dilation ==================== This example illustrates greyscale mathematical morphology. .. GENERATED FROM PYTHON SOURCE LINES 7-41 .. image-sg:: /advanced/image_processing/auto_examples/images/sphx_glr_plot_greyscale_dilation_001.png :alt: plot greyscale dilation :srcset: /advanced/image_processing/auto_examples/images/sphx_glr_plot_greyscale_dilation_001.png :class: sphx-glr-single-img .. code-block:: default import numpy as np import scipy as sp import matplotlib.pyplot as plt im = np.zeros((64, 64)) np.random.seed(2) x, y = (63*np.random.random((2, 8))).astype(int) im[x, y] = np.arange(8) bigger_points = sp.ndimage.grey_dilation(im, size=(5, 5), structure=np.ones((5, 5))) square = np.zeros((16, 16)) square[4:-4, 4:-4] = 1 dist = sp.ndimage.distance_transform_bf(square) dilate_dist = sp.ndimage.grey_dilation(dist, size=(3, 3), \ structure=np.ones((3, 3))) plt.figure(figsize=(12.5, 3)) plt.subplot(141) plt.imshow(im, interpolation='nearest', cmap=plt.cm.nipy_spectral) plt.axis('off') plt.subplot(142) plt.imshow(bigger_points, interpolation='nearest', cmap=plt.cm.nipy_spectral) plt.axis('off') plt.subplot(143) plt.imshow(dist, interpolation='nearest', cmap=plt.cm.nipy_spectral) plt.axis('off') plt.subplot(144) plt.imshow(dilate_dist, interpolation='nearest', cmap=plt.cm.nipy_spectral) 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() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.064 seconds) .. _sphx_glr_download_advanced_image_processing_auto_examples_plot_greyscale_dilation.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_greyscale_dilation.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_greyscale_dilation.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_