
- 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 − Otsu Thresholding
Otsu's method is an automatic image thresholding technique used in computer vision and image processing, which is named after its creator Nobuyuki Otsu. The algorithm determines a single intensity threshold that effectively divides pixels into two distinct classes: foreground and background.
This calculates an optimal threshold by maximizing the variance between the two classes of pixels that are separated by the threshold.
The scikit image library provides the threshold_otsu() function within its filters module to compute the threshold value based on Otsu's method.
Using the skimage.filters.threshold_otsu() function
The filters.threshold_otsu() function is used to calculate a threshold value based on Otsu's method. It requires either the image or hist parameter to be provided. If hist is provided, it uses the provided histogram to determine the thresholds. If the image is provided, it computes the histogram from the image.
Syntax
Following is the syntax of this function −
skimage.filters.threshold_otsu(image=None, nbins=256, *, hist=None)
Parameters
Here are the details about the function parameters −
- Image (N, M[, â¦, P]) ndarray: An optional grayscale input image.
- nbins (int): An optional integer specifying the number of bins used to calculate the histogram. This value is ignored for integer arrays.
- hist (array, or 2-tuple of arrays): An optional input histogram from which to determine the threshold, and optionally, a corresponding array of bin center intensities. If no histogram is provided, the function will compute it from the image.
Return value
The function returns the calculated upper threshold value (float). All pixels in the image with an intensity higher than this threshold are assumed to be foreground.
Note: It is important to note that the input image must be a grayscale image.
Example
Here is an example of using Otsu's thresholding method to separate an image into foreground and background based on pixel intensities −
import matplotlib.pyplot as plt from skimage import io from skimage.filters import threshold_otsu # Load the image in grayscale image = io.imread('Images/black rose.jpg', as_gray=True) # Calculate the Otsu threshold thresh = threshold_otsu(image) # Create a binary image using the threshold binary = image > thresh # Create subplots for original image, histogram, and thresholded image fig, axes = plt.subplots(ncols=3, figsize=(12, 2.5)) ax = axes.ravel() # Display the original image ax[0].imshow(image, cmap=plt.cm.gray) ax[0].set_title('Original') ax[0].axis('off') # Plot the histogram with the Otsu threshold marked in red ax[1].hist(image.ravel(), bins=256) ax[1].set_title('Histogram') ax[1].axvline(thresh, color='r') # Display the thresholded image ax[2].imshow(binary, cmap=plt.cm.gray) ax[2].set_title('Thresholded') ax[2].axis('off') # Show the subplots plt.show()
Output
Example
Here is another example of applying Otsu's thresholding method to separate an image into foreground and background using a 3D image −
import matplotlib.pyplot as plt from skimage import exposure, data from skimage.morphology import ball from skimage.filters import threshold_otsu # Load the brain image and rescale intensity brain = exposure.rescale_intensity(data.brain().astype(float)) # Calculate the Otsu threshold for the brain image thresh = threshold_otsu(brain) # Create a binary image using the Otsu threshold binary = brain >= thresh # Create subplots for original and thresholded images fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(10, 5), sharex=True, sharey=True) ax = axes.ravel() # Choose a slice index for visualization slice_index = 3 # Display the original image ax[0].imshow(brain[slice_index], cmap=plt.cm.gray) ax[0].set_title('Original') ax[0].axis('off') # Display the Otsu thresholded image ax[1].imshow(binary[slice_index], cmap=plt.cm.gray) ax[1].set_title(f'Otsu ($t={thresh}$)') ax[1].axis('off') fig.tight_layout() plt.show()