Scikit Image - Isotopic Closing and Opening of an Image



Isotropic closing and opening are binary morphological image processing operations that utilize circular structuring elements and an optimization technique involving the Euclidean distance map to efficiently close gaps, connect regions, and remove small objects in binary images. These operations are optimized for faster execution when using large circular structuring elements.

Scikit-image provides the isotropic_closing() and isotropic_opening() functions in its morphology module to perform the binary morphological closing and opening operations using large circular structuring elements.

Using the skimage.morphology.isotropic_closing() function

The isotropic_closing() function is used to perform binary morphological closing on an input binary image.

It works the same as the skimage.morphology.binary_closing() function but it is optimized for faster closing operations with large circular structuring elements. This is achieved by applying a threshold to the inverted image's Euclidean distance map based on the implementation function scipy.ndimage.distance_transform_edt.

Syntax

Following is the syntax of this function −

skimage.morphology.isotropic_closing(image, radius, out=None, spacing=None)

Parameters

  • image (ndarray): This is the binary input image on which the dilation operation is performed.
  • radius (float): This parameter specifies the radius by which regions in the binary image should be dilated.
  • out (ndarray of bool, optional): an optional output array where the result of the dilation operation will be stored. If you pass None, a new array will be created to store the result.
  • spacing (float or sequence of float, optional): This parameter specifies the spacing of elements along each dimension of the input image. If provided as a single number, it will be used for all axes. If not specified, a grid spacing of unity is implied.

Return Value

It returns the closed image as an ndarray of boolean values (True and False).

Example

The following example demonstrates how to use the morphology.isotropic_closing() function to perform binary morphological closing on an input binary image.

import numpy as np
from skimage import morphology, io
from skimage.util import invert
import matplotlib.pyplot as plt

# Load an input image
image = io.imread('Images/Circle2.jpg', as_gray=True)

# Invert the original image to get the white object.
binary_image = invert(image)

# Perform isotropic closing with a radius of 0.5
closed_image = morphology.isotropic_closing(binary_image, 0.5)

# Display the input and closed images
fig, axes = plt.subplots(1, 2, figsize=(10, 5))
ax = axes.ravel()

# Display the input image
ax[0].imshow(image, cmap=plt.cm.gray)
ax[0].set_title('Original Image')
ax[0].set_axis_off()

# Display the closed image
ax[1].imshow(closed_image, cmap=plt.cm.gray)
ax[1].set_title('Isotropic Closed Image')
ax[1].set_axis_off()
plt.tight_layout()
plt.show()

Output

On executing the above program, you will get the following output −

Using the skimage.morphology.isotropic_opening() function

The morphology.isotropic_opening() function is used to perform binary morphological opening on an input binary image.

It works the same as the skimage.morphology.binary_opening() function but it is optimized for faster closing operations with large circular structuring elements. This is achieved by applying a threshold to the inverted image's Euclidean distance map based on the implementation function scipy.ndimage.distance_transform_edt.

Syntax

Following is the syntax of this function−

skimage.morphology.isotropic_opening(image, radius, out=None, spacing=None)

Parameters

  • image (ndarray): This is the binary input image on which the dilation operation is performed.
  • radius (float): This parameter specifies the radius by which regions in the binary image should be dilated.
  • out (ndarray of bool, optional): an optional output array where the result of the dilation operation will be stored. If you pass None, a new array will be created to store the result.
  • spacing (float or sequence of float, optional): This parameter specifies the spacing of elements along each dimension of the input image. If provided as a single number, it will be used for all axes. If not specified, a grid spacing of unity is implied.

Return Value

It returns the opened image as an ndarray of boolean values (True and False).

Example

The following example demonstrates how to use the morphology.isotropic_opening() function to perform binary morphological opening on an input binary image.

import numpy as np
from skimage import morphology, io
from skimage.util import invert
import matplotlib.pyplot as plt

# Load an input image
image = io.imread('Images/Circle2.jpg', as_gray=True)

# Invert the original image to get the white object.
binary_image = invert(image)

# Perform isotropic opening with a radius of 1
opened_image = morphology.isotropic_opening(binary_image, 1)

# Display the input and opened images
fig, axes = plt.subplots(1, 2, figsize=(10, 5))
ax = axes.ravel()

# Display the input image
ax[0].imshow(image, cmap=plt.cm.gray)
ax[0].set_title('Original Image')
ax[0].set_axis_off()

# Display the opened image
ax[1].imshow(opened_image, cmap=plt.cm.gray)
ax[1].set_title('Isotropic Opened Image')
ax[1].set_axis_off()
plt.tight_layout()
plt.show()

Output

On executing the above program, you will get the following output −

Advertisements