Andrew:
After you binarized the image, there were some small holes in it that gave loops in the skeleton. I took the largest blob (to get rid of a noise speck) and then filled the holes in the remaining blob. Corrected code:
img= imread('25g 1 10 PSI 5 MMS.jpg');
imgray = rgb2gray(img);
subplot(2, 2, 1);
imshow(imgray, []);
BW = im2bw(imgray, 0.8);
BW = bwareafilt(BW, 1);
BW = imfill(BW, 'holes');
subplot(2, 2, 2);
imshow(BW, []);
minBranchLength = round(sum(BW(:)) / 2)
skelImage = bwskel(BW, 'MinBranchLength', minBranchLength);
subplot(2, 2, 3);
imshow(skelImage)
g = gcf;
g.WindowState = 'maximized'
Best Answer