FairScan icon FairScan
/
Blog

Better scans with automatic white balance

November 29, 2026

Have you ever scanned a document with FairScan and ended up with a colored background when you expected it to be white? Before version 2.5, that was a common problem when using the app with less-than-ideal lighting. It's not just about white: all colors can be affected but the difference is more noticeable in white areas. And so far, FairScan didn't try to fix colors at all.

Why colors don't always look right

The problem is a general one in photography: how to ensure that the colors that we see as humans are correctly reproduced in a digital image? The light illuminating a scene may have a color cast, which can have a big impact on how everything appears.

If you scan a document lying on your desk at night, with the help of a lamp, you may get a document that looks yellow. It depends on the lamp, but it's common for home lamps to have a yellow ("warm") tint. Similarly, you may get a bluish tint without any artificial light, for example on a cloudy day or early in the morning.

Our brain naturally compensates for the color of the light, so we don't always notice how much it affects the colors around us. When you're in a room with strongly colored lighting, you may have a hard time distinguishing colors, but you can still tell (most of the time) what is supposed to be white under normal lighting. When capturing a picture with your phone, something similar has to happen to avoid unpleasant surprises when you see the result later. This process is called "white balance", and apps that capture an image usually get an image with some automatic white balance. So far, FairScan relied on that, but that's not always enough.

Warm image, FairScan 2.4 Cold image, FairScan 2.4

When you scan a document, your device captures an image that contains elements other than the document: the entire scene is taken into account when evaluating how colors should be adjusted. The device may also take a few seconds to adjust to a change in light or framing. When you see a picture that contains a document, you may perceive the document background as white, but when you crop the image and see the document with a white border, then you realize it's not white at all. This is where FairScan can do better than the camera: it knows where the document is. It can ignore the desk, the wall and the other objects in the scene, and adjust the colors based on the paper alone.

Finding the right correction

Knowing where to look is only half of the problem: someone still has to decide what the correction should be. Sophisticated photo editing apps let users manually adjust the white balance of a photo with one or two sliders. That's something I wanted to avoid in FairScan. The app prioritizes solutions that are fast and easy to use rather than trying to achieve perfect results: it should therefore handle white balance automatically.

There are many ways to do that, from basic algorithms to "AI-powered" solutions. As a first step for this particular problem, I strongly preferred to stay on something simple.

One of the simplest white balance methods is called gray world. It's based on the assumption that the average color of a scene is neutral (gray). The correction to apply to an image is simply derived from its average color. Actually, I already implemented this method in FairScan to determine whether a document should be processed with a color or grayscale filter. It works rather well for that task because it can help detect whether most pixels of an image have more or less the same color, whatever it is. However, I didn't really consider applying it to adjust the colors of the scan. For a document where the main colors are white and another color, gray world would consider that the neutral color is between those two, and that can often make things worse than in the original image. For many documents, the assumption behind gray world simply doesn't hold. In version 2.5, the color detection now relies on the analysis described below instead, with a slightly better result.

Image processed with gray world

Another simple method is called "white patch". Its textbook version assumes that the brightest pixel of an image should appear as white: based on that, we can compute a correction that should be applied to the whole image. That's fragile though: one reflection or one noisy pixel, and the whole correction is off. For FairScan, I implemented a variant of it: it selects the brightest 15% of the pixels in the document (not of the whole scene) and uses their typical color (the median) as the reference. It works well in the context of a document scanning app based on the assumption that many documents have a significant proportion of white, even when there are a lot of colored areas.

Warm image, FairScan 2.5 Cold image, FairScan 2.5

Knowing when not to correct

There are cases where this assumption doesn't hold though, for example when the document has no white areas, or when they don't cover enough of its brightest pixels. In those cases, applying the white patch method turns the brightest area into something closer to gray, and all the colors of the image can look different. That's generally not what we want, and avoiding a correction is a better choice.

Strongly colored image

To handle that, I added an automatic criterion to decide whether to apply the white balance correction. First, the correction is limited: FairScan never changes the color of a pixel by more than about a third. Then, once it is applied, FairScan looks at the brightest pixels of the document and checks whether they are sufficiently close to neutral. On a normal document, that works: a slightly yellow sheet is easily brought back to white, and the check passes. But when the brightest areas are strongly colored, like a mostly green image, the limited correction can't make them neutral: the check fails and the image is left as it is. Without the limit, even that vivid green image would end up neutral, and the check would approve a correction that ruins it.

When automatic white balance gets it wrong

The automatic white balance system I just described gives good results. I developed it based on a few dozen images and then validated it on the 800+ images of my dataset. It's still not perfect though.

A typical case where it gives a non-ideal result is a pale colored sheet of paper: all the brightest pixels have the same pale color, and they become close to white after the correction, so the color effectively disappears in the output scan. A more vivid color, however, would be out of reach of the limited correction: it stays as it is. In fact, I don't see how to automatically distinguish a colored sheet from a white document under colored lighting, based on the image alone, and perhaps this behavior is acceptable. In case you wonder: the popular scanning apps I tried show similar behavior.

Pale colored image

There are also more complex cases. Think of a scene where multiple lights with different colors come into play: a single color correction cannot fully adjust the whole image. I guess that's another limit I have to accept.

As a kind of safety net, FairScan now has a new "original" filter (in addition to "color", "grayscale" and "black & white"): if you face a case where automatic "enhancement" of the image is too bad, you can disable it. As always with bad scans, feel free to share them with me so that I can improve the app.


In the end, almost all documents have more natural-looking colors. White balance makes a noticeable difference, even with a rather simple algorithm. That's the kind of thing I wish I had done earlier. FairScan's "color" filter is still basic. I hope I can find effective solutions to reduce shadows and improve contrast to achieve results that are at least as good as those of the "grayscale" filter. The challenge is always to avoid degrading the original image. Ideally, FairScan would produce PDF files with a perfectly uniform background. I don't know how to achieve that yet, but I'll keep looking for ways to improve it.