Script and language identification for handwritten document images