Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Add an option to manipulate the contrast with GraphicsMagick #121

Open
juanfra684 opened this issue Jun 1, 2017 · 2 comments
Open

Add an option to manipulate the contrast with GraphicsMagick #121

juanfra684 opened this issue Jun 1, 2017 · 2 comments

Comments

@juanfra684
Copy link
Contributor

juanfra684 commented Jun 1, 2017

I've some scanned documents (sorry, I can't share the files) which due to the settings used for the scanning, have lost contrast and detail. The text was originally black and now is dark gray and the background is light gray instead of white. I can even see slightly the lines of text of the other page. pdf2djvu converts correctly the files and includes these annoying details.

I've been playing with the images (extracted with pdftoppm) in GIMP and the "Brightness-Contrast" tool enhances the image quality a lot. Just changing the contrast to 15, the text is black again and the light gray background disappears. Everything looks like a PDF with real text, not as a scanned image.

The GIMP tool is just a simple GUI which hides the details of the real tool, the levels editor. GraphicsMagick has a similar option to change the levels. You're already using GM to change the foreground colors, can you add another option to change the levels with GM?.

If you want to test the results, use some pdf with that problems, extract the images and open one with GIMP. Select Color and Brightness-Contrast. Check the option Preview and use the slider to change the contrast. In my case, the best setting is 15. Now click in the button Edit these settings as levels. In the first slider the settings are 22, 1.0 and 233. Close GIMP and run gm convert theimagefromthepdf -level '22,1.0,91%' output.png. I'm using a percentage here instead of the original number because GM's MaxRGB isn't 255 on my computer and the conversion fails. Use a cross multiplication to calculate the percentage.

@juanfra684
Copy link
Contributor Author

I found an image with similar problems in Archive.org. The settings are: gm convert original.png -level '0,0.55,85%' cleaned.png

Original:
original
Cleaned:
cleaned

@rbrito
Copy link

rbrito commented Apr 12, 2018

A change like this would really, really rock and would prevent me from having to "unpack" the PDF files with poppler's pdftoppm, like @juanfra684, run this kind of imagemagick/graphicsmagick and recompress the PDF files...

I have, countless times, wanted just this, but using the --monochrome option of pdf2djvu just created dithered images that made things hard to compress (and noisy)...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

3 participants