MATLAB Image Dilation

Ammar Ali Feb 15, 2024
MATLAB Image Dilation

This tutorial will discuss the dilation of an image using the imdilate() function in Matlab.

Dilate an Image Using the imdilate() Function in MATLAB

Dilation increases the number of pixels in an image by adding pixels on the boundaries of objects present inside an image.

We can use Matlab’s built-in function imdilate() to dilate an image in Matlab. To dilate an image, we have to provide the input image and the structuring element. A structuring element can be a vertical line, a rolling ball, or any other element.

For example, let’s read an image using the imread() function and create a ball-shaped structuring element using the offsetstrel() function and then dilate the image with the rolling ball and then we will show both the original as well as the dilated image using the subplot() function.

See the code below.

original_Image = imread('cameraman.tif');
structuring_element = offsetstrel('ball',5,5);
dilated_Image = imdilate(original_Image,structuring_element);
subplot(1,2,1)
imshow(original_Image)
title('Original Image')
subplot(1,2,2)
imshow(dilated_Image)
title('Dilated Image')

Output:

image dilation using a rolling ball

In the output, the right side image is the dilated image, and you can see the white balls at the edges of the objects present in the image.

The input image can be a grayscale, binary, or packed binary image. The structuring element should be a strel object, offsetstrel object, and array of strel or offsetstrell objects.

By default, the imdilate() function considers the image as not packed, but we can change it to packed using the pakopt property.

By default, the imdilate() function will return the image of the same size as the input image, but we can change the shape of the output image to full dilation using the shape property.

Author: Ammar Ali
Ammar Ali avatar Ammar Ali avatar

Hello! I am Ammar Ali, a programmer here to learn from experience, people, and docs, and create interesting and useful programming content. I mostly create content about Python, Matlab, and Microcontrollers like Arduino and PIC.

LinkedIn Facebook

Related Article - MATLAB Image