.. _example_plot_otsu.py:


============
Thresholding
============

Thresholding is used to create a binary image. This example uses Otsu's method
to calculate the threshold value.

Otsu's method calculates an "optimal" threshold (marked by a red line in the
histogram below) by maximizing the variance between two classes of pixels,
which are separated by the threshold. Equivalently, this threshold minimizes
the intra-class variance.

.. [1] http://en.wikipedia.org/wiki/Otsu's_method


.. image:: images/plot_otsu_1.png
    :align: center


.. literalinclude:: plot_otsu.py
    :lines: 17-



**Python source code:** :download:`download <plot_otsu.py>`
(generated using ``skimage`` |version|)



**IPython Notebook:** :download:`download <./notebook/plot_otsu.ipynb>`
(generated using ``skimage`` |version|)

