
- 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 - Diameter Closing and Opening an Image
Diameter closing and opening are morphological operations based on attribute operators also known as connected operators, which are a family of contour-preserving filtering operations used in mathematical morphology. These operations can be implemented using max-trees, which are hierarchical representations of images.
Diameter closing is particularly useful for removing all dark structures of an image while preserving long and thin structures based on their maximal extension. Whereas, the diameter opening removes all bright structures in an image while preserving larger and thin structures.
The scikit image library provides the diameter_closing() and diameter_opening() functions in the morphology module to perform these diameter closing and opening operations on images.
Using the skimage.morphology.diameter_closing() function
The diameter_closing() function is used to perform a diameter-closing operation on an input image. Diameter closing removes dark structures in an image that have a maximal extension (defined as the maximal extension of their bounding box) smaller than a specified threshold. This operation is also known as Bounding Box Closing and is similar to morphological closing, but it preserves long and thin structures.
Syntax
Following is the syntax of this function −
skimage.morphology.diameter_closing(image, diameter_threshold=8, connectivity=1, parent=None, tree_traverser=None)
Parameters
- image (ndarray): The input image for which the diameter closing operation is to be performed. This image can be of any type.
- diameter_threshold (unsigned int): The maximal extension parameter in the number of pixels. The default value is 8.
- connectivity (unsigned int, optional): The neighborhood connectivity. This parameter specifies the maximum number of orthogonal steps to reach a neighbor. In 2D, it is typically set to 1 for a 4-neighborhood and 2 for an 8-neighborhood. The default value is 1.
- parent (ndarray, int64, optional): A precomputed parent image representing the max tree of the inverted image. Providing a precomputed parent image can speed up the function.
- tree_traverser (1D array, int64, optional): A precomputed traverser where the pixels are ordered such that every pixel is preceded by its parent (except for the root which has no parent). Providing a precomputed traverser can also speed up the function.
Return Value
It returns an output image of the same shape and type as the input image, where the dark structures that meet the diameter threshold criterion have been preserved.
Example
This example creates an image with multiple local minima and then performs a diameter closing operation on it using the morphology.diameter_closing() function.
import numpy as np from skimage.morphology import diameter_closing import matplotlib.pyplot as plt # Create the image w = 12 x, y = np.mgrid[0:w, 0:w] image = 180 + 0.2 * ((x - w/2)**2 + (y - w/2)**2) # Add local minima image[2:3, 1:5] = 160 image[2:4, 9:11] = 140 image[9:11, 2:4] = 120 image[9:10, 9:11] = 100 image[10, 10] = 100 # Convert the image to integer image = image.astype(int) # Perform diameter closing with a threshold of 3 and connectivity=1 closed = diameter_closing(image, 3, connectivity=1) # Display the original and closed images fig, axes = plt.subplots(1, 2, figsize=(10, 5)) ax = axes.ravel() ax[0].imshow(image, cmap=plt.cm.gray) ax[0].set_title('Original Image') ax[1].imshow(closed, cmap=plt.cm.gray) ax[1].set_title('Diameter Closing (Threshold = 3)') plt.tight_layout() plt.show()
Output
On executing the above program, you will get the following output −

Using the skimage.morphology.diameter_opening() function
The diameter_opening() function is used to perform a diameter opening operation on an input image. Diameter opening removes bright structures in an image that have a maximal extension (defined as the maximal extension of their bounding box) smaller than a specified threshold. This operation is also known as Bounding Box Opening and is particularly useful for preserving long and thin structures in an image. It is based on the max-tree representation of the image.
Syntax
Following is the syntax of this function −
skimage.morphology.diameter_opening(image, diameter_threshold=8, connectivity=1, parent=None, tree_traverser=None)
Parameters
- image (ndarray): The input image for which the diameter opening operation is to be performed. This image can be of any type.
- diameter_threshold (unsigned int): The maximal extension parameter in number of pixels. The default value is 8.
- connectivity (unsigned int, optional): The neighborhood connectivity. This parameter specifies the maximum number of orthogonal steps to reach a neighbor. In 2D, it is typically set to 1 for a 4-neighborhood and 2 for an 8-neighborhood. The default value is 1.
- parent (ndarray, int64, optional): A parent image representing the max tree of the input image. The value of each pixel in this image is the index of its parent in the raveled array.
- tree_traverser (1D array, int64, optional): The ordered pixel indices referring to the raveled array. Pixels are ordered such that every pixel is preceded by its parent (except for the root, which has no parent).
Return Value
It returns an output image of the same shape and type as the input image, where the bright structures that meet the diameter threshold criterion have been removed.
Example
The following example demonestrates how to use the morphology.diameter_opening() function to perform the diameter opening of an image.
import numpy as np from skimage.morphology import diameter_opening import matplotlib.pyplot as plt # Create the image w = 12 x, y = np.mgrid[0:w, 0:w] image = 20 - 0.2 * ((x - w/2)**2 + (y - w/2)**2) # Add local maxima image[2:3, 1:5] = 40 image[2:4, 9:11] = 60 image[9:11, 2:4] = 80 image[9:10, 9:11] = 100 image[10, 10] = 100 # Convert the image to integer image = image.astype(int) # Perform diameter opening with a threshold of 3 and connectivity=1 opened = diameter_opening(image, 3, connectivity=1) # Display the original and opened images fig, axes = plt.subplots(1, 2, figsize=(10, 5)) ax = axes.ravel() ax[0].imshow(image, cmap=plt.cm.gray) ax[0].set_title('Original Image') ax[1].imshow(opened, cmap=plt.cm.gray) ax[1].set_title('Diameter Opening (Threshold = 3)') plt.tight_layout() plt.show()
Output
On executing the above program, you will get the following output −
