Javatpoint Logo
Javatpoint Logo

Morphological operations in MATLAB

Morphological operations are methods of image processing that change the form or organization of objects in an image. These procedures are frequently employed for edge identification, noise reduction, and image enhancement.

The Image Processing Toolbox in MATLAB allows you to execute morphological operations and includes functions for dilation, erosion, opening, closure, and other operations.

Types of Morphological Operations:

Dilation: Dilation broadens an image's depicted object boundaries. It entails moving the structuring element, a predetermined shape, over the image and changing each pixel's value to its maximum value.

  • The neighborhood the structuring element defines. Dilation can enlarge items, join damaged pieces, and fill minor gaps.

Erosion: Erosion causes the borders of items in an image to get smaller.

  • The structuring element is moved over the image, and each pixel is changed to have the lowest value possible inside the neighborhood the structuring element has defined.
  • Erosion effectively reduces the size of items, removes noise, and separates little objects from bigger ones.

Opening: Dilation is followed by erosion during the opening process.

  • It is frequently employed to eliminate minor noise and separate items joined by thin bridges.
  • The opening allows for the removal of smaller objects while maintaining the general shape of larger ones.

Closing: Dilation and erosion are the two stages of closure.

  • It is employed to connect almost touching items and fill in tiny spaces between objects.
  • Closing fills in minor holes while maintaining the overall contour of an object.

Gradient: An image's gradient distinguishes between an image's erosion and dilatation.

  • It draws attention to the edges of the picture's objects. Edge detection and segmentation can both benefit from the gradient operation.

Top Hat: The distinction between an image's opening and its original version is known as the top hat of the picture.

  • Smaller than the structuring element, it shows tiny, brilliant structures or details. For improving fine details, top hat filtering is employed.

Bottom Hat: The difference between the original image and its closing is known as the bottom hat of an image.

  • It draws attention to tiny, dark details or structures smaller than the structuring element. Dark details are enhanced by bottom hat filtering.
  • Consider the peculiarities of the objects and noise in your particular image while choosing a structural element (size and shape) for these processes.

Implementation:

  • The rgb2gray function, which transforms a color image into a grayscale version that may be utilized with morphological procedures, has been added to the revised code.
  • Make careful you substitute the correct path to your image file for "flowers.jpg."

Output:

Morphological operations in MATLAB

Note:

Remember that the size and shape of the structural element you select (se in your code) may affect the results of morphological procedures. Try various structure components to get the desired results for your unique image.

Original Image: This subplot will show the loaded imread original color image.

Dilated Image: The grayscale image created by applying dilation (immediate) using the designated structural element will be displayed in this subplot. In the image, things will look bigger or thicker, especially around edges and boundaries.

Eroded Image: This subplot will display the grayscale image produced by erosion (improve) using the same structural element. Small details may be lost, and objects in the image appear thinner or more degraded.

Opened Image: The outcome of opening (imopening) the grayscale image will be shown in this subplot. The image is initially eroded and then enlarged during this process. It preserves the environment by removing tiny things and noise.

Dilation Implementation:

The program stores a binary image in the variable binary_image by reading it from a file called "binary_image.jpg."

  • The steel function is used to define a structuring element (se).
  • A 3x3 square structural element is produced in this situation. The structuring element defines the neighborhood that the dilation operation will cover.
  • Using the specified structuring element se, the imdilate function applies the dilation operation to the binary_image. The variable dilated_image holds the outcome.
  • The original binary and dilated images are shown side by side in a 1x2 grid of subplots using the subplot and imshow tools.
  • The subplots' titles are provided via the title function.

Output:

Morphological operations in MATLAB
  • Two photos will be shown side by side using the code. The right subplot will display the outcome of the dilation process, and the left will display the original binary image.
  • The left subplot will have the title "Original Binary Image," and the right subplot will have "Dilated Image."

Erosion: Erosion is the opposite of dilatation; it causes local items to be separated and shrinks regional limits. Small noisy patches can be removed via erosion. You can use the improved function in MATLAB.

Output:

Morphological operations in MATLAB

Using the previously established structure element se, the erosion operation is carried out by the code on the binary_image. The variable eroded_image contains the erosion's outcome.

  • The original binary image and the eroded image are shown side by side in a grid of subplots using the imshow and subplot routines.
  • The subplots' titles are provided via the title function. The right subplot will be titled "Eroded Image," and the left will be titled "Original Binary Image."

Closing and Opening: Closing is a dilatation followed by erosion, and it is effective for conserving larger structures while reducing minor noise. Contrarily, closure is a dilatation followed by erosion and effectively fills small gaps in objects. For opening and shutting, MATLAB offers the functions open and close.

Output:

Morphological operations in MATLAB
  • The code uses the designated structural element se to carry out the opening operation on the binary_image. The variable opened_image contains the outcome of the opening procedure.
  • Similarly, the code utilizes the same structural element to conduct the closure operation on the binary_image. The closed_image variable contains the outcome of the closing operation.
  • The original binary image, the opened image, and the closed image are displayed side by side in a 1x3 grid of subplots using the subplot and imshow functions.
  • The subplots' titles are provided via the title function. The left subplot will be titled "Original Binary Image," the middle subplot "Opened Image," and the right subplot "Closed Image."

Miss transformation: This process matches patterns in binary images, called the Hit-or-Miss transformation. It aids in the detection of specific patterns that are indicated by two structuring elements. You can employ MATLAB's whitish function.

Morphological operations in MATLAB

A binary template for the hit-or-miss transformation is defined in the code. The template specifies the pattern to be matched in the binary image, a 3x3 matrix of ones and zeros.

  • Using the provided template, the binary_image is transformed using the hit-or-miss method by the whitish function. The variable matched_image contains the transformation's outcome.
  • The original binary and matched images are shown side by side in a grid of subplots using the subplot and imshow routines.
  • The subplots' titles are provided via the title function. The right subplot will be titled "Matched Image," and the left will be titled "Original Binary.






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA