Image Erosion and Dilation with Scikit-Image

  • Share this:

Code introduction


The function first applies erosion to the input image using the erosion function from scikit-image's morphology module, then applies dilation using the dilation function, and finally returns the image after erosion followed by dilation.


Technology Stack : scikit-image, morphology, util, io

Code Type : Image processing

Code Difficulty : Intermediate


                
                    
def erode_dilate(arg1, arg2, arg3):
    """
    This function applies erosion and dilation to an image using scikit-image's morphological operations.
    :param arg1: The input image.
    :param arg2: The structuring element for erosion.
    :param arg3: The structuring element for dilation.
    :return: The resulting image after erosion followed by dilation.
    """
    from skimage import morphology
    from skimage import util
    from skimage import io

    # Load the input image
    image = io.imread(arg1)

    # Perform erosion
    eroded_image = morphology.erosion(image, arg2)

    # Perform dilation
    dilated_image = morphology.dilation(eroded_image, arg3)

    return dilated_image