binaryImage = imread('7.bmp');
binaryImage = im2bw(binaryImage); % 将二值图像转换为逻辑图像 skeletonImage = bwmorph(binaryImage,'skel',Inf);
connectivity = bwconncomp(skeletonImage);
skeletonImage(connectivity.PixelIdxList{cellfun(@numel, connectivity.PixelIdxList) < 3}) = 0;
pixelSize = 0.1; stripeLengths = cellfun(@numel, connectivity.PixelIdxList) .* pixelSize; stripeLengths(skeletonImage(connectivity.PixelIdxList)) = stripeLengths(skeletonImage(connectivity.PixelIdxList)) * 2; stripeLengths(stripeLengths < 0.483) = [];
remainingStripes = skeletonImage; remainingStripes(connectivity.PixelIdxList(stripeLengths < 0.483)) = 0;
imshow(remainingStripes);

读取二进制图像 binaryImage = imread7bmp; 骨架化处理 skeletonImage = bwmorphbinaryImageskelInf; 获取所有像素的连通性 connectivity = bwconncompskeletonImage; 消除分支条纹 skeletonImageconnectivityPixelIdxListcellfunnumel con