.. 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 ` to download the full example code or to run this example in your browser via Binder .. 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.503 seconds) .. _sphx_glr_download_auto_examples_filters_plot_hysteresis.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/scikit-image/scikit-image/v0.23.2?filepath=notebooks/auto_examples/filters/plot_hysteresis.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_hysteresis.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_hysteresis.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_