How to make a scanned file with black background, white

Hello,
i have made a scan of a book and in the scan the background is all black. I want to print this file now and avoid that my ink is going to waste, so i thought turning it white is the solution. How can i do that with manjaro applications? Its 40 pages so it would be good if it does that for the pages alltogether.

Thank you to all of you in advance. I would really appreciate your help.

Maybe something like

magick *.png -negate %d_inverted.png

from the containing directory and assuming they were pngs.
You would also need imagemagick installed first.

3 Likes

Itā€™s a pdf-file and i tried it but nothing happened? I assume that i had to insert the fileā€™s name to where the star is.

You mean the book was smaller than the scan area and now there is something like a large black border around what you actually want?

imagemagick - there are many tools in this same box :slightly_smiling_face:

I recently used
display
to crop some images
after I failed to find an easy to use more modern tool.

Itā€™s a bit awkward to use - dialogs appear only upon click and will only be present when you hold the mouse button

You could also automate this when the to be cropped area is at the same place in all pictures.

convert
is the tool to do that with

ImageMagick v6 Examples

There is also text recognition software that could extract the text from the scanned pdf file(s).
Probably overkill in terms of time needed to get out of it what you want.

You guessed what my problem is from the little confusing description. Thank you very much. I find it a bit hard to understand how to use this tool and i couldnā€™t find the two tools in the listed examples yet?

display your_picture.pdf

look at the link - plenty of examples there

right click anywhere in the picture shows a menu, click again and it is gone
left click shows another, floating menu which only exists as long as you hold the button
(as it used to be back in the day ā€¦)

There should be many graphic programs which can crop a picture - I ended up using this one.

convert
is a command line tool -
mogrify is another

but the function they provide can be accessed via
display
in a graphical manner

all part of imagemagick

gimp can certainly do it - but it is no less awkward to use if you have never worked with it.

:point_down: ā€¦

magick *.pdf -negate %d_inverted.pdf

All deprecated in favor of magick now.

1 Like

ā€¦ but then the text is white on black - with a white border around it :grimacing:
kind of like ā€œdark modeā€

Aha - I have imagemagick installed - I used it as I said.
But the magick command is not present.

(this is not on Manjaro but on the not newest version of Mint
itā€™s imagemagick version 6)

ImageMagick version 7 will unify these commands under the magick command.

1 Like

Yes - now that I have been told and have read about it, I know.

Itā€™s probably still not easy peasy to automate this process without investing some time to try and test the results and try again ā€¦
It looks like the .pdf needs to be cropped - the black border needs to be cut off.

Since itā€™s a scan one could assume that the position of the to be cropped area doesnā€™t change too much or even stays the same for each scanned page.

Still, for 40 pages it takes less than 10 minutes to do every page by hand - once you got the hang of it via the rather unfamiliar GUI.

I also found out that there is a fork of imagemagick with pretty much the same functionality and look and feel:

graphicsmagick

GraphicsMagick Image Processing System

Now I have both installed - but still not imagemagick version 7
since I am not actively using Manjaro - and Mint does not offer it.

It might be available via a PPA (unless youā€™re on LMDE).

ā€”

What Iā€™d suggest is selecting the scan area, to avoid having to trim the images (too much). Some scanner software can (sometimes) do this automatically; I think XSane* is one; Iā€™ll have to have another play with my scanner to check this.

* Iā€™ll have to check this actually works in Wayland. I think it does but havenā€™t used the scanner for a while.

Thanks for caring!
But I donā€™t want it, donā€™t need it.
Version 6 works just fine :wink:

That would be a way when he still has got the book.
I bet he doesnā€™t.
And it takes even longer to do it all over again than just to crop each picture which is already there.

Iā€™d have to go, with the book, to a copy shop, because I donā€™t own a scanner.

That is why I just use my phones camera and then use the tool to crop the pictures to only contain the subject matter and perhaps resize them and turn them to black and white before printing or e-mailing ā€¦

1 Like

I tend to print from GIMPā€¦
So if we screenshot a post (with Manjaro dark formatting) here, I can first desaturate, then invert to get dark text on light.

If thereā€™s anything needs cropping, do that - then adjust the levels to clean up (whiten) the paper, and curve it so that the contrast looks good - but not too extreme.

Finally, a pencil tool can white over any blemishes remaining (maybe the W logo and the cursor).

  • Using ImageMagik, you can adjust a command to crop like this:
āÆ magick copy.jpg -crop 650x150+60+0 copy-crop.jpg


copy-crop

How did you get on with the cropping?
negative-crop

~/Desktop
āÆ magick copy.jpg -channel RGB -negate negative.jpg

~/Desktop                                                                 
āÆ magick negative.jpg -crop 650x150+60+0 negative-crop.jpg

Itā€™d be easy to wrap these in a bash script.

1 Like

To extract images from a PDF there is also:

$ pdfimages my.pdf images_out -png
1 Like

I donā€™t know if this is of any help or interest but as an experiment I uploaded a scan of a book page to https://lmarena.ai/ (or https://chatbot-arena.web.app/ is the experimental interface) and gave the prompt "Please extract the text from this image", in my opinion the result was an impressive and accurate reproduction of the text.

There are several AI Chatbots to choose from to find the one that best suits you needs or preferences. You may have to adjust the prompt to your needs.

OP has got the scans in the form of .pdf files.
He just wants / needs to remove a black border
which is a residue from the scanned area being bigger than the scanned book,
so as not to having to print all that useless black, wasting ink in the process.

Itā€™s a fairly simple crop job.

No need for AI - which could also be leading into copyright terrain, since you are dealing with the content of the text now -
content of a whole book even ā€¦ and submitting it to ā€œsomeoneā€ online for processing

2 Likes

Apologies, after text recognition was mentioned I got carried away trying the ā€˜AIā€™ chatbot option without referring back to the initial post.

Hello again, iā€™m sorry i was offline for long. Thank you all for your messages. Iā€™m really grateful for them. I will try to follow your advices Nachlese and hopefully report back in a few minutes.

What does that mean exactly, do i put it somewhere else. In front of the command starting with ā€œmagickā€?

Iā€™m not sure, if i want to crop the pictures. Can you explain to me what the above command does exactly? Iā€™m sorry, but iā€™m not sure how to use the link you sent me, to find examples that match my wanted operation. Iā€™m not to familiar with the terminal either. I manage to copy certain commands to it, but thatā€™s basically it. I would really appreciate if you can help me out further.