Text-image alignment for historical handwritten documents