如何使用 MATLAB 查找二进制图像的内部和外部骨架?
骨架化是将二值图像中的前景区域减少为骨架残余的过程,该过程在很大程度上保留了原始区域的范围和连通性,同时丢弃了大部分原始前景像素。在本文中,我们将了解如何使用 MATLAB 内置函数查找二值图像的内部和外部骨架。
细化:细化是对二值图像执行的形态学操作。它从二值图像中删除一些选定的前景像素,从而使图像变薄。在数学上,它是二值图像的差异和对同一二值图像应用的命中或未命中变换的结果。
- 图像的内骨架:每个二值图像都可以被无限次细化。内部结构是在无限次应用细化操作直到结果图像为 1 像素厚时获得的。最终得到二值图像的底层内骨架。
- 图像的外部骨架:图像的外部骨架仅由边界组成,图像的内部像素被去除。它与边缘检测不同,因为在边缘检测中,我们检测所有内部边缘以及边界边缘。在外部骨架中查找结果仅由外部边界组成,并且所有内部像素都被删除。
使用的函数:
- imread( ) 内置函数用于读取图像。
- rgb2gray( ) 内置函数用于将 RGB 彩色图像转换为灰度图像。
- bwmorph( ) 内置函数用于查找图像的骨架。
- imtool( ) 内置函数用于显示图像。
例子:
Matlab
% Find Skeleton of a binary image.
% read the image.
k=imread('skeleton.png');
% Convert into grayscale.
k=rgb2gray(k);
% apply morphological operation.
k1=bwmorph(k,'skel',Inf);
% display original image.
imtool(k);
% display skeleton of image.
imtool(k1);
Matlab
% MATLAB code for remove
% inner pixels of image.
% read the image.
k=imread('skeleton.png');
% Convert into grayscale.
k=rgb2gray(k);
% Apply morphological operation.
k2=bwmorph(k,'remove',Inf);
% display original image.
imtool(k);
% display boundary image.
imtool(k2);
输出:

图 1:输入图像

图 2:输出图像

图 3:GFGlogo 的结果
例子:
MATLAB
% MATLAB code for remove
% inner pixels of image.
% read the image.
k=imread('skeleton.png');
% Convert into grayscale.
k=rgb2gray(k);
% Apply morphological operation.
k2=bwmorph(k,'remove',Inf);
% display original image.
imtool(k);
% display boundary image.
imtool(k2);
输出:

图 4:输入图像

图 5:输出图像

图 6:GFGlogo 上的结果