Compressing and enhancing hand-written notes
image-processingk-means-clusteringcolor-quantizationpythonpdf
Abstraction: k-means color quantization pipeline to clean and compress handwritten note scans
Key points:
noteshrink.pyreduces 7.2 MB scanned PNG pages to ~121 KB while improving visual clarity by removing bleed-through and noise- Background color identified by finding the mode of a 5% pixel sample after reducing bit depth to 6 bits/channel to create robust bins
- Foreground isolation uses HSV colorspace thresholding (value diff > 0.3 or saturation diff > 0.2 from background) rather than RGB Euclidean distance, correctly handling bleed-through vs. ink
- Foreground color palette chosen by k-means clustering (k=7 clusters for 8-color output) in RGB space; each pixel mapped to its nearest cluster center
- Final output is an indexed-color PNG, further reduced by running optipng/pngcrush/pngquant; pages assembled into PDF via ImageMagick
- Four example PDFs averaged ~130 KB/page output; tool is on GitHub as
mzucker/noteshrink
Connections: Color Quantization · K Means Clustering · Image Processing
Source: https://mzucker.github.io/2016/09/20/noteshrink.html