
- 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 − Rolling-ball Algorithm
The rolling-ball algorithm is a powerful tool for estimating the background intensity of a grayscale image with uneven exposure. This algorithm was originally proposed by Stanley R. Sternberg in 1983, and this algorithm is frequently used in biomedical image processing.
This algorithm works like a filter and is quite intuitive. It treats the image as if it were a surface comprised of unit-sized blocks stacked on top of each other instead of individual pixels. The number of these blocks, and thus the height of the surface is determined by the intensity of the pixel.
To determine the background intensity at a specific pixel position, a ball is submerged under the surface at that position. The apex of the ball, once completely covered by blocks, provides the background intensity at that location. By rolling this ball beneath the surface, background values can be obtained for the entire image.
Scikit-Image Implementation
Scikit-image library implements a general version of this rolling-ball algorithm. Unlike the traditional approach using only balls, this implementation allows the use of arbitrary shapes as kernels. Additionally, it is designed to operate on n-dimensional ndimages, which means it can be applied to a wide range of image types, including RGB images. Furthermore, it provides the flexibility to filter image stacks along any or all spatial dimensions.
Using the skimage.restoration.rolling_ball() function
To estimate the background intensity of an image with uneven exposure, you can utilize the skimage.restoration.rolling_ball() function. This function applies a rolling or translational operation to a kernel, calculating the background intensity for an ndimage.
Syntax
Here's the syntax −
skimage.restoration.rolling_ball(image, *, radius=100, kernel=None, nansafe=False, num_threads=None)
Parameters
Following is the explanation of the parameters of this function −
- image (ndarray): The input image to be filtered.
- radius (int, optional): The radius of a ball-shaped kernel that is rolled or translated in the image. If the kernel parameter is provided, this radius parameter is not used.
- kernel (ndarray, optional): An optional kernel can be provided instead of using the default ball-shaped kernel. This kernel should have the same number of dimensions as the input image. The kernel is filled with the intensity of the kernel at that position.
- nansafe (bool, optional): By default, this parameter is set to False. If set to False, the function assumes that none of the values in the input image are np.nan. Using nansafe=False can result in a faster implementation.
- num_threads (int, optional): This parameter specifies the maximum number of threads to use for computation. If None, the function will use the OpenMP default value, typically equal to the maximum number of virtual cores. note: It's an upper limit to the number of threads, and the exact number is determined by the system's OpenMP library.
Return value
The function returns a ndarray background. The estimated background of the input image. This output will be an array of the same shape as the input image.
Example
The following example demonstrates how to use the restoration.rolling_ball function to estimate the background of a dark background image −
import matplotlib.pyplot as plt from skimage import io, restoration # Load an image image = io.imread('Images/Cloud.jpg') # Use the rolling-ball algorithm to estimate the background background = restoration.rolling_ball(image) # Create a figure with three subplots for visualization fig, ax = plt.subplots(1, 3, figsize=(12, 4)) # Plot the original image ax[0].imshow(image, cmap='gray') ax[0].set_title('Original Image') ax[0].axis('off') # Plot the estimated background ax[1].imshow(background, cmap='gray') ax[1].set_title('Estimated Background') ax[1].axis('off') # Calculate and plot the resulting image (original - background) result = image - background ax[2].imshow(result, cmap='gray') ax[2].set_title('Result (Original - Background)') ax[2].axis('off') plt.tight_layout() plt.show()
Output
Example
This example demonstrates how the rolling-ball algorithm can be applied to images with bright backgrounds −
import matplotlib.pyplot as plt from skimage import io, restoration, util # Load an image image = io.imread('Images/hand writting.jpg') image_inverted = util.invert(image) # Estimate the background of the inverted image using the rolling-ball algorithm background_inverted = restoration.rolling_ball(image_inverted, radius=45) # Calculate the filtered image by subtracting the estimated background from the inverted image filtered_image_inverted = image_inverted - background_inverted # Invert both the filtered image and the estimated background to restore their original orientation filtered_image = util.invert(filtered_image_inverted) background = util.invert(background_inverted) # Create a figure with three subplots for visualization fig, ax = plt.subplots(1, 3, figsize=(12, 4)) # Plot the original image ax[0].imshow(image, cmap='gray') ax[0].set_title('Original Image') ax[0].axis('off') # Plot the estimated background ax[1].imshow(background, cmap='gray') ax[1].set_title('Estimated Background') ax[1].axis('off') # Plot the resulting filtered image ax[2].imshow(filtered_image, cmap='gray') ax[2].set_title('Result (Filtered Image)') ax[2].axis('off') plt.tight_layout() plt.show()
Output
Specifying a Custom Kernel for the Rolling-Ball Algorithm
The rolling_ball() function in Scikit-Image typically uses a ball-shaped kernel as the default choice. However, in certain scenarios, such as when the intensity dimension varies significantly from the spatial dimensions or when the image dimensions may have different meanings(e.g., one dimension represents a stack counter in an image stack), using a ball-shaped kernel may be too restrictive.
To address such situations, the rolling_ball function includes a kernel argument, which allows you to specify a custom kernel. This kernel should have the same dimensionality as the image but can have a different shape. It's important to note that the dimensionality should match, even if the shape varies.
Scikit-Image provides two default kernels to help with kernel creation −
1. ball_kernel: Specifies a ball-shaped kernel, which is also used as the default kernel.
Its syntax is as follows −
skimage.restoration.ball_kernel(radius, ndim)
- radius (int): The radius of the ball.
- ndim (int): The number of dimensions of the ball. It should match the dimensionality of the image.
2. ellipsoid_kernel: Specifies an ellipsoid-shaped kernel.
Its syntax is as follows −
skimage.restoration.ellipsoid_kernel(shape, intensity)
- shape (array-like): Determines the length of the principal axis of the ellipsoid, excluding the intensity axis. It specifies the dimensions of the ellipsoid kernel.
- intensity (int): Determines the length of the intensity axis of the ellipsoid.
Example
This example applies the rolling-ball algorithm to the image using the custom ellipsoid-shaped kernel to estimate the background −
import matplotlib.pyplot as plt from skimage import io, restoration # Load an image image = io.imread('Images/Cloud.jpg') # Create an ellipsoid-shaped kernel with specified dimensions kernel_size = (70.5 * 2, 70.5 * 2) kernel_radius = 70.5 * 2 kernel = restoration.ellipsoid_kernel(kernel_size, kernel_radius) # Use the rolling-ball algorithm to estimate the background background = restoration.rolling_ball(image, kernel=kernel) # Create a figure with three subplots for visualization fig, ax = plt.subplots(1, 3, figsize=(12, 4)) # Plot the original image ax[0].imshow(image, cmap='gray') ax[0].set_title('Original Image') ax[0].axis('off') # Plot the estimated background ax[1].imshow(background, cmap='gray') ax[1].set_title('Background') ax[1].axis('off') # Calculate and plot the resulting image (original - background) result = image - background ax[2].imshow(result, cmap='gray') ax[2].set_title('Result (Original - Background)') ax[2].axis('off') plt.tight_layout() plt.show()