Intelligent Pen: A least cost search approach to Stroke Extraction in Historical Documents