Tesseract reads white text. Two things broke it
96.3%
words right on white on black, no prep
Black on white: 96.1%. No need to invert.
Dark color sets read like black on white
| Colors | As it is | Invert flag off |
|---|---|---|
| Black on white (the control) | 96.1% | 96.1% |
| White on black | 96.3% | 0.5% |
| Light gray on dark gray (code editor) | 96.4% | 0.7% |
| Gray on near black | 96.3% | 0.8% |
| White on blue | 96.3% | 1.4% |
| White on green | 96.3% | 1.2% |
| Dark band over a white page | 96.4% | 41.6% |
| White on transparent | 14.9% | 14.9% |
Each row is the same 591 words in 10 screenshots. Only the colors change.
At 2x, every row but the transparent one read 96.6%.
Trap 1: the invert flag set to 0
tesseract shot.png - \
-c tessedit_do_invert=0
The Tesseract FAQ suggests this flag for speed. On white on black it printed junk, with no error:
Tee ee Case aura eeu hea ee Cont uke Cee euls|
- What it turns off: a second read of each weak line, from an inverted copy. That is how Tesseract 5 reads white text.
- The dark band page: 41.6%. Its white half holds 42.3% of the words.
-
Same trap, new name: 5.5.4 points to
-c invert_threshold=0instead. It gave the same text on all 80 shots. - The fix: delete the flag. For what it saves in time, see Tesseract batch processing.
Invert it yourself and keep the flag? No
I inverted each shot whose mean gray was under 128, then ran the flag. Two color sets failed:
- White on green: 1.5%. Its mean gray is 152 to 155, so the test left it as it was.
- Dark band over a white page: 57.9%. One test for the whole image cannot fit both halves.
Tesseract decides line by line, so it got both right. All 6 dark sets together: 74.1% with this trick, 96.3% with no flag.
Trap 2: white text on a transparent PNG
A logo, a cutout or a caption layer often has no background. Tesseract read 14.9% of those words, and 33.2% at 2x. On one shot it printed:
Talat et ister Sireret thet night, ard me mae engaged Upan our taeet ard
Put it on black first:
magick shot.png -background black \
-flatten flat.png
tesseract flat.png -
Flattened on black, the 10 shots read 96.1%, as good as black on white.
Flattened on white, they read 0 words. A gray copy, which drops the transparency, read 82.9% after inverting.
The same fix in Python
from PIL import Image
import pytesseract
img = Image.open("shot.png").convert("RGBA")
black = Image.new("RGBA", img.size, "black")
print(pytesseract.image_to_string(Image.alpha_composite(black, img)))
As printed, on one transparent shot: 59 of 60 words right, as with magick.
Inverting first gained nothing
| Step before Tesseract | Words right |
|---|---|
| None | 96.3% |
| Invert every shot | 96.2% |
| Invert if the mean gray is under 128 | 96.2% |
| Otsu black and white | 94.8% |
-c invert_threshold=1
|
96.3% |
-
invert_threshold=1tries nearly every line both ways. Its text was the same as no flag, byte for byte, on all 80 shots. - On black on white, inverting did no harm: 96.3%, against 96.1%.
Our Actor reads dark screens, not clear PNGs
PDF OCR to Markdown, our Apify Actor, takes PNG files too. On 3 blocks of each color set, it read 97.8% of words on all 7 opaque sets.
It read nothing on the transparent shots: it puts them on white, so white text disappears. Flatten them on black first. A fix is on our list.
- Images and scanned pages: $0.006 each. Digital pages: free. Plus a $0.00005 start fee a run at the default 1 GB.
- On Apify's free plan, it stops at 20 pages a run and 50 a month.
What I did not test
- Tesseract 4 and older, and other OCR tools.
- Dark text on a transparent PNG.
- White text on photos, video frames and gradients. For subtitles, see video OCR.
- Color fringes from Windows ClearType, and other languages.
- Speed: other jobs kept the Mac busy.
How I tested it
- Text: 10 blocks of 56 to 65 words from The Adventures of Sherlock Holmes (1892, public domain), from Wikisource. 591 words in all.
- Shots: headless Chromium drew each block at 14 px, 560 px wide, at 1x and 2x. 8 color sets, the same blocks in each. 160 PNG files.
- Colors: #222 on #fff, #fff on #000, #d4d4d4 on #1e1e1e, #8e8e93 on #1c1c1e, #fff on #0a84ff, #fff on #34c759, a #1e1e1e band over #fff, and #fff on transparent.
- Tesseract: the command line, default page mode, English tessdata_fast 4.1.0, one thread, one run at a time.
- Words right: words that match the text, in any order, with case and punctuation kept.
- The Actor: its own code at commit 5dcdaa5f, run on this Mac on blocks 1 to 3 of each set at 1x, with text output.
- Each tesseract, magick and Python command on this page ran as printed.
- Tesseract 5.5.4 (Leptonica 1.87.0), ImageMagick 7.1.2-11, Chromium 153.0.8010.12, Pillow 12.1.1 (13.0.0 for the Python code), pytesseract 0.3.13, Python 3.14.7, macOS 26.6 (arm64).
- Scripts and results stay in our private repo, in research/bench/tesseract-white-text-2026-11-23/.
Sources
- Tesseract docs: inverting images. It says to use dark text on light for Tesseract 4. In this test, 5.5.4 did not need it.
- Tesseract FAQ: can I increase speed of OCR? (tessedit_do_invert=0)
-
tesseract --print-parameters: tessedit_do_invert (deprecated, use invert_threshold) and invert_threshold (0.7) - pytesseract
- ImageMagick -flatten
- We make the Apify Actor, and none of the other tools here.
Questions people ask
Can Tesseract read white text on a black background?
Yes. Tesseract 5.5.4 read 96.3% of the words on our white on black screenshots with no prep, and 96.1% on the same text in black on white.
Should I invert the image before Tesseract?
Not for a dark screenshot. Inverting first read 96.2% of words on our 6 dark color sets, against 96.3% with no step. Tesseract tries an inverted copy of each weak line on its own.
Why does Tesseract print junk for white text?
Look for -c tessedit_do_invert=0 or -c invert_threshold=0 in your command or config. With either, white on black read 0.5% of words, and Tesseract printed junk with no error. Delete the flag.
How do I OCR white text on a transparent PNG?
Put it on black first: magick shot.png -background black -flatten flat.png, then tesseract flat.png -. As it was, Tesseract read 14.9% of the words. Flattened, it read 96.1%.
Two ways to skip the work
Run it yourself. Our Apify Actor turns scanned PDFs and images into Markdown, tables included.
Or send us the scan. Tack, our AI, does the job for $29, up to 50 pages. First page free.