I am trying to process numerous images through tesseract. Nonetheless, I have just discovered that by increasing the dpi I obtained better results. I have tried looking throughout StackOverflow on how I could possibly increase the dpi of an image, but all of the answers that I have found involved in changing the dpi while saving the file so something similar to this:
img.save('test.png', dpi=(300.0, 300.0))
Therefore I was wondering If it is possible to do this without necessarily saving the file.
I have trying doing the following:
image = Image.open('test.png', dpi=(300.0, 300.0))
but sadly it doesn't work
Thank you very much for your help in advance.
The PNG format stores DPI information in a metadata chunk in the file, it's called a "pHYs" chunk. So, you're really looking for a tool which can edit or add these kinds of chunks in/to PNG files without reading the image data itself.
A library which can do that is libpng and there exist Python bindings for it.
You might also want to check out this question which addresses the same problem. Apparently there are tools like IrfanView and ImageMagick which can change PNG files, like putting a pHYs metadata block in it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With