
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/filters/plot_hysteresis.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        :ref:`Go to the end <sphx_glr_download_auto_examples_filters_plot_hysteresis.py>`
        to download the full example code.

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

.. _sphx_glr_auto_examples_filters_plot_hysteresis.py:


=======================
Hysteresis thresholding
=======================

*Hysteresis* is the lagging of an effect---a kind of inertia. In the
context of thresholding, it means that areas above some *low* threshold
are considered to be above the threshold *if* they are also connected
to areas above a higher, more stringent, threshold. They can thus be
seen as continuations of these high-confidence areas.

Below, we compare normal thresholding to hysteresis thresholding.
Notice how hysteresis allows one to ignore "noise" outside of the coin
edges.

.. GENERATED FROM PYTHON SOURCE LINES 16-50



.. image-sg:: /auto_examples/filters/images/sphx_glr_plot_hysteresis_001.png
   :alt: Original image, Sobel edges, Low threshold, Hysteresis threshold
   :srcset: /auto_examples/filters/images/sphx_glr_plot_hysteresis_001.png
   :class: sphx-glr-single-img





.. code-block:: Python


    import matplotlib.pyplot as plt
    from skimage import data, filters

    fig, ax = plt.subplots(nrows=2, ncols=2)

    image = data.coins()
    edges = filters.sobel(image)

    low = 0.1
    high = 0.35

    lowt = (edges > low).astype(int)
    hight = (edges > high).astype(int)
    hyst = filters.apply_hysteresis_threshold(edges, low, high)

    ax[0, 0].imshow(image, cmap='gray')
    ax[0, 0].set_title('Original image')

    ax[0, 1].imshow(edges, cmap='magma')
    ax[0, 1].set_title('Sobel edges')

    ax[1, 0].imshow(lowt, cmap='magma')
    ax[1, 0].set_title('Low threshold')

    ax[1, 1].imshow(hight + hyst, cmap='magma')
    ax[1, 1].set_title('Hysteresis threshold')

    for a in ax.ravel():
        a.axis('off')

    plt.tight_layout()

    plt.show()


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

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


.. _sphx_glr_download_auto_examples_filters_plot_hysteresis.py:

.. only:: html

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

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

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

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

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

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

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


.. only:: html

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

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