Matlab提取二值图像骨架、骨骼

本篇文章对Matlab提取二值图像骨架的方法进行总结:

方法一:bwskel()

(1) 首先需要读取待处理图像,并对其进行二值化处理。

I = imread('2.jpg');
I=rgb2gray(I);%图像灰度化
figure;imshow(I)
title('原始图像','FontSize',14)
%骨架化二值图像:为了使原始图像适合于骨架化,对图像进行反转,以使对象变亮而背景变暗。 然后,将结果图像二值化。
Icomplement = imcomplement(I);
BW = imbinarize(Icomplement);
figure;imshow(BW)
title('二值图像','FontSize',14)

 (2) 使用bwskel执行二值图像的骨架化

out = bwskel(BW);
figure;imshow(out)
title('骨架图像1','FontSize',14)

 

 可以看到上图红框部分存在突出的毛刺部分,可以使用MinBranchLength参数消除面积小于指定大小的毛刺。

out2 = bwskel(BW,'MinBranchLength',50);
figure;imshow(out2)
title('骨架图像2','FontSize',14)

方法二:bwmorph()

(1) 首先需要读取待处理图像,并对其进行二值化处理。方法如上。

(2) 使用bwmorph的‘skel’参数进行二值图像的骨架化,可以看到有许多的毛刺。

bw_skel=bwmorph(BW,'skel',Inf);
figure;imshow(bw_skel)
title('骨架图像3','FontSize',14)

 (3) 使用bwmorph的‘thin’参数进行二值图像的骨架化。

% result1 = bwmorph(BW,'thin',10);
result2 = bwmorph(BW,'thin',Inf);
figure;
imshow(result2)
title('骨架图像4','FontSize',14)

 

 以上就是matlab提取二值图像骨架的方法。如果有不懂的小伙伴儿,欢迎评论留言或者私信,代码订制也可私信博主。

猜你喜欢

转载自blog.csdn.net/qq_37904531/article/details/131175378