
- Scikit Image – Introduction
- Scikit Image - Image Processing
- Scikit Image - Numpy Images
- Scikit Image - Image datatypes
- Scikit Image - Using Plugins
- Scikit Image - Image Handlings
- Scikit Image - Reading Images
- Scikit Image - Writing Images
- Scikit Image - Displaying Images
- Scikit Image - Image Collections
- Scikit Image - Image Stack
- Scikit Image - Multi Image
- Scikit Image - Data Visualization
- Scikit Image - Using Matplotlib
- Scikit Image - Using Ploty
- Scikit Image - Using Mayavi
- Scikit Image - Using Napari
- Scikit Image - Color Manipulation
- Scikit Image - Alpha Channel
- Scikit Image - Conversion b/w Color & Gray Values
- Scikit Image - Conversion b/w RGB & HSV
- Scikit Image - Conversion to CIE-LAB Color Space
- Scikit Image - Conversion from CIE-LAB Color Space
- Scikit Image - Conversion to luv Color Space
- Scikit Image - Conversion from luv Color Space
- Scikit Image - Image Inversion
- Scikit Image - Painting Images with Labels
- Scikit Image - Contrast & Exposure
- Scikit Image - Contrast
- Scikit Image - Contrast enhancement
- Scikit Image - Exposure
- Scikit Image - Histogram Matching
- Scikit Image - Histogram Equalization
- Scikit Image - Local Histogram Equalization
- Scikit Image - Tinting gray-scale images
- Scikit Image - Image Transformation
- Scikit Image - Scaling an image
- Scikit Image - Rotating an Image
- Scikit Image - Warping an Image
- Scikit Image - Affine Transform
- Scikit Image - Piecewise Affine Transform
- Scikit Image - ProjectiveTransform
- Scikit Image - EuclideanTransform
- Scikit Image - Radon Transform
- Scikit Image - Line Hough Transform
- Scikit Image - Probabilistic Hough Transform
- Scikit Image - Circular Hough Transforms
- Scikit Image - Elliptical Hough Transforms
- Scikit Image - Polynomial Transform
- Scikit Image - Image Pyramids
- Scikit Image - Pyramid Gaussian Transform
- Scikit Image - Pyramid Laplacian Transform
- Scikit Image - Swirl Transform
- Scikit Image - Morphological Operations
- Scikit Image - Erosion
- Scikit Image - Dilation
- Scikit Image - Black & White Tophat Morphologies
- Scikit Image - Convex Hull
- Scikit Image - Generating footprints
- Scikit Image - Isotopic Dilation & Erosion
- Scikit Image - Isotopic Closing & Opening of an Image
- Scikit Image - Skelitonizing an Image
- Scikit Image - Morphological Thinning
- Scikit Image - Masking an image
- Scikit Image - Area Closing & Opening of an Image
- Scikit Image - Diameter Closing & Opening of an Image
- Scikit Image - Morphological reconstruction of an Image
- Scikit Image - Finding local Maxima
- Scikit Image - Finding local Minima
- Scikit Image - Removing Small Holes from an Image
- Scikit Image - Removing Small Objects from an Image
- Scikit Image - Filters
- Scikit Image - Image Filters
- Scikit Image - Median Filter
- Scikit Image - Mean Filters
- Scikit Image - Morphological gray-level Filters
- Scikit Image - Gabor Filter
- Scikit Image - Gaussian Filter
- Scikit Image - Butterworth Filter
- Scikit Image - Frangi Filter
- Scikit Image - Hessian Filter
- Scikit Image - Meijering Neuriteness Filter
- Scikit Image - Sato Filter
- Scikit Image - Sobel Filter
- Scikit Image - Farid Filter
- Scikit Image - Scharr Filter
- Scikit Image - Unsharp Mask Filter
- Scikit Image - Roberts Cross Operator
- Scikit Image - Lapalace Operator
- Scikit Image - Window Functions With Images
- Scikit Image - Thresholding
- Scikit Image - Applying Threshold
- Scikit Image - Otsu Thresholding
- Scikit Image - Local thresholding
- Scikit Image - Hysteresis Thresholding
- Scikit Image - Li thresholding
- Scikit Image - Multi-Otsu Thresholding
- Scikit Image - Niblack and Sauvola Thresholding
- Scikit Image - Restoring Images
- Scikit Image - Rolling-ball Algorithm
- Scikit Image - Denoising an Image
- Scikit Image - Wavelet Denoising
- Scikit Image - Non-local means denoising for preserving textures
- Scikit Image - Calibrating Denoisers Using J-Invariance
- Scikit Image - Total Variation Denoising
- Scikit Image - Shift-invariant wavelet denoising
- Scikit Image - Image Deconvolution
- Scikit Image - Richardson-Lucy Deconvolution
- Scikit Image - Recover the original from a wrapped phase image
- Scikit Image - Image Inpainting
- Scikit Image - Registering Images
- Scikit Image - Image Registration
- Scikit Image - Masked Normalized Cross-Correlation
- Scikit Image - Registration using optical flow
- Scikit Image - Assemble images with simple image stitching
- Scikit Image - Registration using Polar and Log-Polar
- Scikit Image - Feature Detection
- Scikit Image - Dense DAISY Feature Description
- Scikit Image - Histogram of Oriented Gradients
- Scikit Image - Template Matching
- Scikit Image - CENSURE Feature Detector
- Scikit Image - BRIEF Binary Descriptor
- Scikit Image - SIFT Feature Detector and Descriptor Extractor
- Scikit Image - GLCM Texture Features
- Scikit Image - Shape Index
- Scikit Image - Sliding Window Histogram
- Scikit Image - Finding Contour
- Scikit Image - Texture Classification Using Local Binary Pattern
- Scikit Image - Texture Classification Using Multi-Block Local Binary Pattern
- Scikit Image - Active Contour Model
- Scikit Image - Canny Edge Detection
- Scikit Image - Marching Cubes
- Scikit Image - Foerstner Corner Detection
- Scikit Image - Harris Corner Detection
- Scikit Image - Extracting FAST Corners
- Scikit Image - Shi-Tomasi Corner Detection
- Scikit Image - Haar Like Feature Detection
- Scikit Image - Haar Feature detection of coordinates
- Scikit Image - Hessian matrix
- Scikit Image - ORB feature Detection
- Scikit Image - Additional Concepts
- Scikit Image - Render text onto an image
- Scikit Image - Face detection using a cascade classifier
- Scikit Image - Face classification using Haar-like feature descriptor
- Scikit Image - Visual image comparison
- Scikit Image - Exploring Region Properties With Pandas
Scikit Image − Li thresholding
Li thresholding, introduced by Li and Lee in 1993, offers a criterion for determining the optimal threshold to separate the foreground and background in an image. Their approach minimizes the cross-entropy between the foreground and its mean and the background and its mean, which would find the best threshold in most situations.
Before 1998, the common approach to finding this threshold was to test all possible thresholds and select the one with the lowest cross-entropy. However, in 1998, Li and Tam introduced an iterative method to more quickly find the optimum point by using the slope of the cross-entropy. This iterative method, known as the threshold_li() function, is implemented in the scikit-image library as part of its filters module.
Using the skimage.filters.threshold_li() function
The filters.threshold_li() function is used to compute a threshold value for a grayscale input image using Li's iterative Minimum Cross Entropy method −
Syntax
Following is the syntax of this function −
skimage.filters.threshold_li(image, *, tolerance=None, initial_guess=None, iter_callback=None)
Parameters
Here are the details of the function parameters −
- image (N, M[, â¦, P]) ndarray: This parameter represents the grayscale input image. It should be a NumPy array.
- tolerance (optional): This is a float value that specifies when the computation should finish. The algorithm stops when the change in the threshold in an iteration is less than this value. By default, this is the smallest difference between intensity values in the image.
- initial_guess (optional): Li's iterative method uses gradient descent to find the optimal threshold. When an image's intensity histogram contains multiple modes (peaks), gradient descent can get stuck in a local optimum. Providing an initial guess for the threshold can help the algorithm find the globally optimal threshold. You can provide an initial guess as a float value or a callable function that takes an array of image intensities and returns a float value. Examples of valid callables include numpy.mean (default), lambda arr: numpy.quantile(arr, 0.95), or even skimage.filters.threshold_otsu().
- iter_callback (optional): This is a callable function that will be called on the threshold at every iteration of the algorithm.
Return value
The function returns a single value, this is a float value representing the upper threshold value. All pixels with an intensity higher than this threshold are assumed to belong to the foreground, while those with an intensity lower than or equal to this threshold are considered part of the background.
Example
Here's a simple example of how to separate the foreground and background regions in the image using the filters.threshold_li() function −
import numpy as np from skimage import io, filters import matplotlib.pyplot as plt # Load a grayscale image image = io.imread('Images/logo.png', as_gray=True) # Compute the threshold using Li's method threshold = filters.threshold_li(image) # Use the threshold to separate the foreground and background regions in the image. # Pixel intensities higher than the threshold value is foreground foreground = image > threshold # Pixel intensities lower than or equal to the threshold value is background background = image < threshold # Display the original image, foreground, and background fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(10, 10)) ax = axes.ravel() ax[0].imshow(image, cmap=plt.cm.gray) ax[0].set_title('Original') ax[1].imshow(foreground, cmap=plt.cm.gray) ax[1].set_title('Foreground') ax[2].imshow(background, cmap=plt.cm.gray) ax[2].set_title('Background') for a in ax: a.axis('off') plt.tight_layout() plt.show()
Output
Example
This example demonstration, the concept of cross-entropy and its optimization using Li's iterative method. It's important to note that we are using the private function _cross_entropy(), which is not intended for production code as it may change in the future −
import numpy as np import matplotlib.pyplot as plt from skimage import io, filters from skimage.filters.thresholding import _cross_entropy # Load the input image image = io.imread('Images/albert-einstein-15.jpg', as_gray=True) # Possible threshold values thresholds = np.arange(np.min(image) + 1.5, np.max(image) - 1.5) # cross-entropy for the image at all possible thresholds entropies = [_cross_entropy(image, t) for t in thresholds] optimal_threshold = thresholds[np.argmin(entropies)] fig, ax = plt.subplots(1, 3, figsize=(10, 8)) ax[0].imshow(image, cmap='gray') ax[0].set_title('image') ax[0].set_axis_off() ax[1].imshow(image > optimal_threshold, cmap='gray') ax[1].set_title('thresholded') ax[1].set_axis_off() ax[2].plot(thresholds, entropies) ax[2].set_xlabel('thresholds') ax[2].set_ylabel('cross-entropy') ax[2].vlines(optimal_threshold, ymin=np.min(entropies) - 0.05 * np.ptp(entropies), ymax=np.max(entropies) - 0.05 * np.ptp(entropies)) ax[2].set_title('optimal threshold') fig.tight_layout() print('The brute force optimal threshold is:', optimal_threshold) print('The computed optimal threshold is:', filters.threshold_li(image)) plt.show()
Output
The brute force optimal threshold is: 63.5 The computed optimal threshold is: 62.93757319319864