So I think I v found a way to do it. Its working for now, but still have to test it out on a bigger scale. So what i did was the following,
% code
• Get skeleton image,
• Find branch points,
• Dilate branch points,
• Subtract dilated branch points from skeleton image,
• Use connected components with bwconncomp for the broken off branches,
• Use regionprops to get get pixel list of each of the branches,
• Make an image for an isolated single branch,
• Add the image of branch points to the isolated single branch image,
• Use dilation to merge the closest branch points to the single branch,
• Use thin to put dilated branch points back to single pixels,
• use clean to get rid of branch point pixels,
• skeleton the remainding single branch,
• loop through for all branches
its endpoints are now correctly back to the way they were. So this was only tested on a small scale.