simoneamico
Joined 7 months ago
Joined 7 months ago
In short, by checking 3 simple signals veil can now distinguish a scan with overlaid OCR text from a native PDF with images. The first is whether the image covers more than 40% of the page, meaning it dominates the surface. The second is whether there are more than 200 characters, enough to be a document and not just a cover. The third is whether the image is predominantly blank paper rather than a photograph, verified by sampling the luminance of the pixels. When all three conditions are true, the image is no longer protected and the inversion applies normally. The same detection runs in the export path too. Thanks again for the file, importjelly.
The choice to never invert raster images isn't a compromise, it's the design decision. The problem veil solves is exactly that: every dark mode reader today inverts everything, and the result on photos, histology, color charts, scans is unusable. Preserving all images is the conservative choice, and for my target (people reading scientific papers, medical reports, technical manuals) it's the right one.
It's absolutely true that there's a subset of raster images, like diagrams with white backgrounds and black lines, that would benefit from inversion. I could be wrong, but in my experience they're a minority, and the cost of accidentally inverting the wrong one (a medical photo, a color chart) is much higher than the benefit of inverting a black and white diagram, from my point of view. For now the per-page toggle covers those cases.
Your approach with a classifier makes a lot more sense for the generic web, where you're dealing with arbitrary <img> tags with no structural metadata, and there you have no choice but to look at what's inside. PDFs are a more favorable problem.
A case where a classifier like yours would be an interesting complement is purely vector diagrams, drawn with PDF path operators, not raster images. Veil inverts those along with the text because from the format's perspective they're indistinguishable. In practice they're rare enough that the per-page toggle handles them, but it's the honest limitation of the approach.
veil: https://veil.simoneamico.com
UX Engineer Log: https://simoneamico.com