A computationally effcient method for edge thinning and linking using endpoints