How to convert an image of a document into a high contrast black and white image?

-1

What I mean is, let's imagine I take a photograph of a document, diagram or whatever. Now if I put this photo into a document it feels weird, even though the background color is white it's not as white as the background of the document (pdf for instance).

So what I'd like is something like a script for gimp or something alike, that takes my image and converts the dark blue or black zones into pure black, then everyting else goes to pure white.

This way I expect it to feel less weird when putting it into a document.

Thank you so much for your help!

Ivan A.

Posted 2020-01-30T13:08:16.953

Reputation: 11

Question was closed 2020-02-03T16:19:44.343

We are not a script writing service, what have you tried? – Moab – 2020-01-30T13:14:40.063

Convert it to a gif that only has two indexed colors or similar. – Seth – 2020-01-30T13:26:59.250

Obviously you're not a script writting service. But I thought that maybe somebody had done something like this before, so that person could share his or her experience. – Ivan A. – 2020-01-30T13:56:44.417

Thank you for the insight Seth! I'll try – Ivan A. – 2020-01-30T13:57:19.433

2"I thought that maybe somebody had done something like this before, so that person could share his or her experience" Unless you post what you have tried, you are asking someone to write you a script, edit you question to include what you have tried. – Moab – 2020-01-30T17:30:10.577

Answers

2

With ImageMagick:

In-place version:

[magick] mogrify -level 20%,80% yourfile.jpg

New file version:

[magick] convert input.jpg -level 20%,80% output.jpg

Where 20% and 80% are the luminosity under/over which everything becomes pure black/white.

Depending on version used, commands are mogrify and convert (old version) or magick mogrify and magick convert (recent versions).

See here for the gory details.

xenoid

Posted 2020-01-30T13:08:16.953

Reputation: 7 552

Software recommendations do not make good answers here, this should be a comment instead – Moab – 2020-01-30T17:31:11.853

1@moab It's not a software recommendation, it''s a one-line script :) – xenoid – 2020-01-30T22:07:33.103

1

The answer from xenoid made me research a little bit about imagemagick (which I didn't know beforehand). After some trial and error I got the (at least for me) optimum process.

First of all we convert our image into grayscale with a threshold of 40%

convert input_image.jpg -colorspace gray -auto-level -threshold 40% output_image.jpg

Then, If there are many small black dots we get rid of the using:

convert output_image.jpg -morphology Close Disk final_image.jpg

And voila, the result is exactly what I expected, there are still many bigger dots there but the result is great. I let some pics down there for you yo see the before and the after.

Before the processing After the processing

Ivan A.

Posted 2020-01-30T13:08:16.953

Reputation: 11