diff --git a/doc/examples/segmentation/plot_thresholding.py b/doc/examples/segmentation/plot_thresholding.py index cae58a32..55abf889 100644 --- a/doc/examples/segmentation/plot_thresholding.py +++ b/doc/examples/segmentation/plot_thresholding.py @@ -6,10 +6,12 @@ Thresholding Thresholding is used to create a binary image from a grayscale image [1]_. Thresholding algorithms can be separated in two categories: - * Global. They are based on the histogram of the pixel intensity of - the image. - * Local. To process a pixel, only the neighboring pixels are used. - These algorithms often require more computation time. + +* Histogram-based. The histogram of the pixel intensity is used and +assumptions may be 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. Scikit-image includes a function to test thresholding algorithms provided in the library. Therefore, in a glance, you can select the best algorithm @@ -18,20 +20,26 @@ for you data, without a deep understanding of their mechanisms. .. [1] https://en.wikipedia.org/wiki/Thresholding_%28image_processing%29 """ +import matplotlib +import matplotlib.pyplot as plt + from skimage.data import page +from skimage.filters import thresholding img = page() # Here, we specify a radius for local thresholding algorithm. # If it is not specified, only global algorithms are called. -fig, ax = mosaic_threshold(img, radius=20, figsize=(10,8), verbose=False) -fig +fig, ax = thresholding.mosaic_threshold(img, radius=20, + figsize=(10,8), verbose=False) +fig.show() """ .. image:: PLOT2RST.current_figure -This example uses Otsu's method [2]_ to calculate the threshold value. +Now, we illustrate how to apply one of these thresholding algorithms +This example uses Otsu's method [2]_. 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, @@ -55,7 +63,6 @@ image = camera() thresh = threshold_otsu(image) binary = image > thresh -#fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(8, 2.5)) fig = plt.figure(figsize=(8, 2.5)) ax1 = plt.subplot(1, 3, 1, adjustable='box-forced') ax2 = plt.subplot(1, 3, 2) @@ -74,3 +81,7 @@ ax3.set_title('Thresholded') ax3.axis('off') plt.show() + +""" +.. image:: PLOT2RST.current_figure +""" diff --git a/skimage/filters/thresholding.py b/skimage/filters/thresholding.py index fcc51b6f..1df0042a 100644 --- a/skimage/filters/thresholding.py +++ b/skimage/filters/thresholding.py @@ -62,7 +62,7 @@ def _mosaic(image, methods=None, figsize=None, num_cols=2, verbose=True): a.axis('off') fig.tight_layout() - plt.close() + #plt.close() return fig, ax