.. _example_segmentation_plot_threshold_adaptive.py:


=====================
Adaptive Thresholding
=====================

Thresholding is the simplest way to segment objects from a background. If that
background is relatively uniform, then you can use a global threshold value to
binarize the image by pixel-intensity. If there's large variation in the
background intensity, however, adaptive thresholding (a.k.a. local or dynamic
thresholding) may produce better results.

Here, we binarize an image using the `threshold_adaptive` function, which
calculates thresholds in regions of size `block_size` surrounding each pixel
(i.e. local neighborhoods). Each threshold value is the weighted mean of the
local neighborhood minus an offset value.


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


.. literalinclude:: plot_threshold_adaptive.py
    :lines: 18-



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



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

