Gray scale dilation operation of gray scale image

  • Define the dilation kernel (i.e. the structural element). A default rectangular inflation kernel can be created using the strel function, or a custom shape and size can be specified using the strel function.
% 定义膨胀核
se = strel('rectangle', [3 3]);

Dilate the original grayscale image. This can be achieved using the imdilate function.

% 对灰度图像进行膨胀操作
dilated_img = imdilate(gray_img, se);

The complete MATLAB code is as follows:

% 读取灰度图像
gray_img = imread('gray_image.png');

% 定义膨胀核
se = strel('rectangle', [3 3]);

% 对灰度图像进行膨胀操作
dilated_img = imdilate(gray_img, se);

% 显示原始图像和膨胀后的图像
figure;
subplot(1, 2, 1);
imshow(gray_img);
title('原始图像');

subplot(1, 2, 2);
imshow(dilated_img);
title('膨胀后的图像');

In this code example, we use the imread function to read a grayscale image, then define a rectangular dilation kernel, use the imdilate function to dilate the original image, and finally use the subplot and imshow functions to combine the original image with the dilated Images are shown in the same figure.

Guess you like

Origin blog.csdn.net/qq_36314279/article/details/129496176