This snippet code denoise and align scanned documents to be used for any purpose including archiving, classification or OCR.
Sample result :
Left side document : Noisy unaligned scanned document image.
Right side document : Denoised and aligned using the snippet code.
You can read article explaining the code :
Scanned Document Preprocessing For Classification and Feature Extraction