Note
Go to the end to download the full example code. or to run this example in your browser via Binder
Thresholding#
Thresholding is used to create a binary image from a grayscale image [1]. It is the simplest way to segment objects from a background.
Thresholding algorithms implemented in scikit-image can be separated in two categories:
Histogram-based. The histogram of the pixels’ intensity is used and certain assumptions are made on the properties of this histogram (e.g. bimodal).
Local. To process a pixel, only the neighboring pixels are used. These algorithms often require more computation time.
If you are not familiar with the details of the different algorithms and the underlying assumptions, it is often difficult to know which algorithm will give the best results. Therefore, Scikit-image includes a function to evaluate thresholding algorithms provided by the library. At a glance, you can select the best algorithm for you data without a deep understanding of their mechanisms.
See also
Presentation on Rank filters.
import matplotlib.pyplot as plt
from skimage import data
from skimage.filters import try_all_threshold
img = data.page()
fig, ax = try_all_threshold(img, figsize=(10, 8), verbose=False)
plt.show()