.. 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_synthetic_data.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_synthetic_data.py>`
        to download the full example code.

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_advanced_image_processing_auto_examples_plot_synthetic_data.py:


Synthetic data
===============

The example generates and displays simple synthetic data.

.. GENERATED FROM PYTHON SOURCE LINES 7-38



.. image-sg:: /advanced/image_processing/auto_examples/images/sphx_glr_plot_synthetic_data_001.png
   :alt: plot synthetic data
   :srcset: /advanced/image_processing/auto_examples/images/sphx_glr_plot_synthetic_data_001.png
   :class: sphx-glr-single-img





.. code-block:: Python


    import numpy as np
    import scipy as sp
    import matplotlib.pyplot as plt

    rng = np.random.default_rng(27446968)
    n = 10
    l = 256
    im = np.zeros((l, l))
    points = l * rng.random((2, n**2))
    im[(points[0]).astype(int), (points[1]).astype(int)] = 1
    im = sp.ndimage.gaussian_filter(im, sigma=l / (4.0 * n))

    mask = im > im.mean()

    label_im, nb_labels = sp.ndimage.label(mask)

    plt.figure(figsize=(9, 3))

    plt.subplot(131)
    plt.imshow(im)
    plt.axis("off")
    plt.subplot(132)
    plt.imshow(mask, cmap="gray")
    plt.axis("off")
    plt.subplot(133)
    plt.imshow(label_im, cmap="nipy_spectral")
    plt.axis("off")

    plt.subplots_adjust(wspace=0.02, hspace=0.02, top=1, bottom=0, left=0, right=1)
    plt.show()


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** (0 minutes 0.079 seconds)


.. _sphx_glr_download_advanced_image_processing_auto_examples_plot_synthetic_data.py:

.. only:: html

  .. container:: sphx-glr-footer sphx-glr-footer-example

    .. container:: sphx-glr-download sphx-glr-download-jupyter

      :download:`Download Jupyter notebook: plot_synthetic_data.ipynb <plot_synthetic_data.ipynb>`

    .. container:: sphx-glr-download sphx-glr-download-python

      :download:`Download Python source code: plot_synthetic_data.py <plot_synthetic_data.py>`

    .. container:: sphx-glr-download sphx-glr-download-zip

      :download:`Download zipped: plot_synthetic_data.zip <plot_synthetic_data.zip>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_