clc; clear all; % read in a sample image -- also see letters.png, bagel.png J=im2double(imread('1.tif'));
% Normalize and Binarization b = imresize(J,[60,60]); th = graythresh(b); BW1 = im2bw(b, th); figure; imshowpair(b, BW1, 'montage');
% the standard skeletonization: skelimg = bwmorph(~BW1,'thin',inf);
bp = bwmorph(skelimg,'branchpoints'); binaryImage = skelimg & ~bp; figure,imshow(binaryImage); I=binaryImage;
[L,num] = bwlabeln(I,8); for i1=num [r,c]=find(bwlabel(I)==2); rc=[r c] endpts=bwmorph(rc,'endpoints'); end