Detect the boundary of a document and normalize it