
- 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 − Mean Filters
Mean filters belong to a category of image processing filters that are used for the smoothing or blurring of an image. They achieve this by replacing each pixel's value with the average (mean) value of the pixel values in its neighborhood. The scikit-image library offers three mean filters within its filters.rank module which are −
- Local Mean (mean()): This filter computes the average gray level by considering all pixels that belong to the structuring element.
- Percentile Mean (mean_percentile()): It selectively uses pixel values falling within the specified percentiles p0 and p1, often set to 10% and 90%.
- Bilateral Mean (mean_bilateral()): This filter only includes pixels within the structuring element whose gray levels fall within the range of g-s0 to g+s1, often defined as g-500 to g+500.
Local mean and percentile mean filters are typically employed for general image smoothing, whereas bilateral mean filters are a preferred choice when the preservation of edges and important image features is critical. Let us discuss about each mean filter below.
Using the skimage.filters.rank.mean function
The filters.rank.mean() function is used to compute the local mean of an image using a specified neighborhood or footprint.
Syntax
Following is the syntax of this function −
skimage.filters.rank.mean(image, footprint, out=None, mask=None, shift_x=False, shift_y=False, shift_z=False)
Parameters
Here are the details of the parameters −
- image: Input image to compute the local mean. It should be a NumPy ndarray with dimensions ([P,] M, N) and dtype (uint8, uint16).
- footprint: The neighborhood or footprint is expressed as a NumPy ndarray of 1's and 0's. This defines the region around each pixel that is used to compute the local mean.
- out (optional): If provided, it should be a NumPy array with the same dimensions as the input image (image). The local mean will be computed and stored in this output array. If not provided (None), a new array will be allocated for the output.
- mask (optional): A mask array that can be used to define the area of the image included in the local neighborhood. It is of type integer or float. Pixels with values greater than 0 in the mask are included in the neighborhood calculation. If not provided (None), the complete image is used by default.
- shift_x, shift_y, shift_z (optional): These parameters specify an offset added to the center point of the footprint. The shift is bounded to the footprint sizes, meaning the center must remain inside the given footprint.
Return value
The function returns the output image, which is a NumPy ndarray of the same data type as the input image (image).
Example
The following example applies the mean filter to the input image using the mean() function −
import matplotlib.pyplot as plt from skimage import io, color from skimage.filters.rank import mean from skimage.morphology import disk from skimage.util import img_as_ubyte # Load the input image image = color.rgb2gray(io.imread('Images/Tajmahal_2.jpg')) image = img_as_ubyte(image) # Define a circular footprint footprint = disk(5) # Apply the mean filter to the image output = mean(image, footprint=footprint) # Plot the original and filtered images side by side fig, axes = plt.subplots(1, 2, figsize=(12, 6)) ax = axes.ravel() # Display the Original Image ax[0].imshow(image, cmap=plt.cm.gray) ax[0].set_title('Original Image') ax[0].axis('off') ax[1].imshow(output, cmap=plt.cm.gray) ax[1].set_title('Mean Filtered Image') ax[1].axis('off') plt.show()
Output
Using the skimage.filters.rank.mean_percentile() function
The filters.rank.mean_percentile() function is used to compute the local mean of an image while considering only the gray values within a specified percentile interval [p0, p1].
Syntax
Following is the syntax of this function −
skimage.filters.rank.mean_percentile(image, footprint, out=None, mask=None, shift_x=False, shift_y=False, p0=0, p1=1)
Parameters
Here are the details of the parameters −
- Image (2-D array (uint8, uint16)): Input image on which the local mean is to be computed.
- Footprint (2-D array): The neighborhood or structuring element expressed as a 2-D array of 1s and 0s.
- out (optional, 2-D array (same dtype as input)): If provided, it should be a NumPy array of the same shape and data type as the input image. The filtered image will be stored in this output array. If not provided (None), a new array will be allocated for the output.
- mask (optional, ndarray): it is a mask array that can be used to define the area of the image included in the local neighborhood. If not provided (None), the complete input image is used by default.
- shift_x, shift_y (int): Offset added to the footprint's center point. The shift is bounded to the footprint sizes, meaning the center must remain inside the given footprint.
- p0, p1 (float in [0, 1]): These parameters define the percentile interval [p0, p1] to be considered for computing the value.
Return value
The function returns an output image, which is a 2-D NumPy array of the same data type as the input image (image). It contains the result of applying the mean percentile filter to the input image.
Example
This example applies the mean percentile filter with specific percentile values (p0 and p1) using the mean_percentile() function −
import matplotlib.pyplot as plt from skimage import io, color from skimage.filters.rank import mean_percentile # Importing the mean_percentile function from skimage.morphology import disk from skimage.util import img_as_ubyte # Load the input image and convert it to grayscale image = color.rgb2gray(io.imread('Images/Tajmahal_2.jpg')) # Convert image to 8-bit unsigned integer format image = img_as_ubyte(image) # Define a circular footprint footprint = disk(5) # Apply the mean percentile filter to the image with specific percentile values (p0 and p1) output = mean_percentile(image, footprint=footprint, p0=0.1, p1=1) # Plot the original and filtered images side by side fig, axes = plt.subplots(1, 2, figsize=(12, 6)) ax = axes.ravel() # Display the Original Image ax[0].imshow(image, cmap=plt.cm.gray) ax[0].set_title('Original Image') ax[0].axis('off') # Display the Mean Percentile Filtered Image ax[1].imshow(output, cmap=plt.cm.gray) ax[1].set_title('Mean Percentile Filtered Image') ax[1].axis('off') plt.show()
Output
Using the skimage.filters.rank.mean_bilateral() function
The filters.rank.mean_bilateral() function is used to apply the flat kernel bilateral filter to images. This filter is used for edge-preserving and noise-reducing image denoising. It averages pixel values based on both spatial closeness and radiometric similarity.
Spatial closeness is determined by the local pixel neighborhood defined by the footprint or structuring element. Radiometric similarity refers to the similarity in gray level. In the context of the bilateral filter, it's defined by the gray level interval [g-s0, g+s1], where g is the gray level of the current pixel.
Only pixels within this gray level interval are considered for averaging.
Syntax
Following is the syntax of this function −
skimage.filters.rank.mean_bilateral(image, footprint, out=None, mask=None, shift_x=False, shift_y=False, s0=10, s1=10)
Here are the details of the parameters −
- Image (2-D array (uint8, uint16)): Input image to be filtered.
- Footprint (2-D array): The neighborhood, expressed as a 2-D array of 1s and 0s, which defines the shape of the local neighborhood or structuring element used in the filter.
- out (optional, 2-D array (same dtype as input)): If provided, it should be a NumPy array of the same shape and data type as the input image. The filtered image will be stored in this output array. If not provided (None), a new array will be allocated for the output.
- mask (optional, ndarray): Mask array that can be used to define the area of the image included in the local neighborhood. If not provided (None), the complete input image is used by default.
- shift_x, shift_y (int): Offset added to the footprint's center point. The shift is bound to the footprint sizes, meaning the center must remain inside the given footprint.
- s0, s1 (int): These parameters define the radiometric similarity interval around the gray value of the center pixel to be considered for computing the filtered value.
Return value
The function returns the output image, which is a 2-D NumPy array of the same data type as the input image (image). It contains the result of applying the mean bilateral filter to the input image.
Example
This example applies the mean bilateral filter with specific radiometric similarity parameters (s0 and s1) using the mean_bilateral() function −
import matplotlib.pyplot as plt from skimage import io, color from skimage.filters.rank import mean_bilateral from skimage.morphology import disk from skimage.util import img_as_ubyte # Load the input image (convert it to grayscale) image = color.rgb2gray(io.imread('Images/Tajmahal_2.jpg')) # Convert image to 8-bit unsigned integer format image = img_as_ubyte(image) # Define a circular footprint (structuring element) footprint = disk(5) # Apply the mean bilateral filter to the image with specific radiometric similarity parameters (s0 and s1) output = mean_bilateral(image, footprint=footprint, s0=500, s1=500) # Plot the original and filtered images side by side fig, axes = plt.subplots(1, 2, figsize=(12, 6)) ax = axes.ravel() # Display the Original Image ax[0].imshow(image, cmap=plt.cm.gray) ax[0].set_title('Original Image') ax[0].axis('off') # Display the Mean Bilateral Filtered Image ax[1].imshow(output, cmap=plt.cm.gray) ax[1].set_title('Mean Bilateral Filtered Image') ax[1].axis('off') plt.show()