Text this: A robust algorithm for template curve estimation based on manifold embedding