.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_packages_scikit-image_auto_examples_plot_threshold.py: Otsu thresholding ================== This example illustrates automatic Otsu thresholding. .. image:: /packages/scikit-image/auto_examples/images/sphx_glr_plot_threshold_001.png :class: sphx-glr-single-img .. code-block:: python import matplotlib.pyplot as plt from skimage import data from skimage import filters from skimage import exposure camera = data.camera() val = filters.threshold_otsu(camera) hist, bins_center = exposure.histogram(camera) plt.figure(figsize=(9, 4)) plt.subplot(131) plt.imshow(camera, cmap='gray', interpolation='nearest') plt.axis('off') plt.subplot(132) plt.imshow(camera < val, cmap='gray', interpolation='nearest') plt.axis('off') plt.subplot(133) plt.plot(bins_center, hist, lw=2) plt.axvline(val, color='k', ls='--') plt.tight_layout() plt.show() **Total running time of the script:** ( 0 minutes 0.104 seconds) .. _sphx_glr_download_packages_scikit-image_auto_examples_plot_threshold.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: plot_threshold.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: plot_threshold.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_