During my PhD, I developed and published an algorithm — together with my advisor and a colleague — to enhance photos of documents captured with digital cameras. These images often suffered from uneven lighting across the page. Our algorithm corrects this by normalizing the illumination, similar to what CamScanner does. The implementation is written in C++ and is available on my GitHub: https://github.com/dmo2000/shading-removal-illustrated-docs.
The method works in four steps:
Detection of low-variation regions: The algorithm first identifies areas in the image with low color variation, which are likely to correspond to blank regions of the paper (i.e., without text or illustrations).
Background clustering: From these low-variation regions, it extracts the cluster most likely to represent the paper's true background.
-
Shading estimation: Once the paper background is identified, the algorithm estimates the shading pattern for the rest of the document, including non-blank areas.
To perform this step, I used a technique known as Natural Neighbor Interpolation (also called Voronoi interpolation). This method is especially useful when data points (in this case, known shading values) are unevenly distributed — a situation similar to how weather data is interpolated from scattered measurement stations.
For the interpolation and related geometric computations, I used the CGAL library. I also relied on data structures from the Boost C++ libraries to support the implementation.
Final enhancement: Finally, the image is enhanced removing the shading obtained in previous step.
The images below shows one example of processing:
Original Image
Cluster with detected background (steps 1 and 2)
Background estimation (step 3)
Final enhancement (step 4)
The complete source code is publicly available on GitHub:
👉 https://github.com/dmo2000/shading-removal-illustrated-docs
The full paper is available at: https://www.researchgate.net/publication/300028589_Shading_Removal_of_Illustrated_Documents