Replace all colours with black, except white

Ask for help and post your question on how to use XnView MP.

Moderators: XnTriq, xnview

Post Reply
mrwul
Posts: 264
Joined: Tue May 25, 2010 7:01 pm

Replace all colours with black, except white

Post by mrwul » Thu Jun 04, 2020 1:12 pm

In screenshots: would there be a way to batch(!) replace all colours with black, except white and then reverse the colours?
white > black
black > white


Example
-
SnagIt-04062020 150027.png

User avatar
xnview
Author of XnView
Posts: 33425
Joined: Mon Oct 13, 2003 7:31 am
Location: France
Contact:

Re: Replace all colours with black, except white

Post by xnview » Sat Jun 06, 2020 7:39 am

sorry but no way
Pierre.

cday
XnThusiast
Posts: 2456
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Replace all colours with black, except white

Post by cday » Sat Jun 06, 2020 9:31 am

xnview wrote:
Sat Jun 06, 2020 7:39 am
sorry but no way
The only way I can see to do this would be to use OCR (Optical Character Recognition) software to the capture the text, and then to use that text in the XnView MP text tool in the Draw function. Probably not a viable solution, I realise.

If you wish to test that method, the excellent Abbyy Screenshot Reader can convert text in a selected area on the screen to text on the clipboard, is a very inexpensive standalone software, and also has a free trial option. :D

mrwul
Posts: 264
Joined: Tue May 25, 2010 7:01 pm

Re: Replace all colours with black, except white

Post by mrwul » Sat Jun 06, 2020 11:35 am

Sorry for the delay: although 'Notify me' is tagged, I never get notifications.

Anyway, thanks for replies.
As for Abbyy Screenshot Reader: I know (and have) that program.
Regretfully it has no 'batch' option.
Programs like Tesseract can OCR images, however, they have to be converted to black characters on white background.

Anyway, thanks again.

cday
XnThusiast
Posts: 2456
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Replace all colours with black, except white

Post by cday » Sat Jun 06, 2020 12:08 pm

mrwul wrote:
Sat Jun 06, 2020 11:35 am
Sorry for the delay: although 'Notify me' is tagged, I never get notifications.

Anyway, thanks for replies.
As for Abbyy Screenshot Reader: I know (and have) that program.
Regretfully it has no 'batch' option.
Programs like Tesseract can OCR images, however, they have to be converted to black characters on white background.

No obvious simple batch process as you say, but in the absence of a better alternative, possibly with resourcefulness there might be ways of streamlining operations to create a semi-batch process?

You could for example join multiple input images vertically, then use the screenshot reader to extract the text from multiple images in a single operation. You might then be able to write those multiple instances of text to a large vertical canvas that can be batch cropped into elements. There are also clipboard tools that enable multiple pieces of text to be stored for use later, if that would help.

If you use NConvert, there might also be possibilities of creating a script to automate a series of custom operations.

It would all depend on the parameters within which you are working, and your motivation to brainstorm and test possible solutions.

Edit:

Another possibility that might be more practical and easily realised could be to use a scripting utility such as AutoHotKey with the Abbyy Screenshot Reader to perform sequences of key strokes, and if necessary mouse operations, to one or more keyboard shortcuts. Depending on your exact requirements, using a macro recorder it should be possible to automate all the operations required that would otherwise have to be performed manually, including stepping to the next file in the folder to open it ready for processing... :D

mrwul
Posts: 264
Joined: Tue May 25, 2010 7:01 pm

Re: Replace all colours with black, except white

Post by mrwul » Sun Jun 07, 2020 11:59 am

Sorry for the delay.

Many thanks for your elaborate reply. Really appreciated.
The big problems is to remove the background and keep the text only, so it can be used for text recognition.
Regretfully, have not found a decent tool that can do that. Regretfully so.

thanks again!

cday
XnThusiast
Posts: 2456
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Replace all colours with black, except white

Post by cday » Sun Jun 07, 2020 1:05 pm

mrwul wrote:
Sun Jun 07, 2020 11:59 am
The big problems is to remove the background and keep the text only, so it can be used for text recognition.
Regretfully, have not found a decent tool that can do that.
If you make a selection around just the text, does the Abbyy text reader not capture the text reliably?


Edit:

You could try the Abbyy screen reader on the enhanced image below, I've made a selection, cropped, used Image > Resize... 200%, and then used Image > Map > Negative, followed by a levels adjustment. All those steps except for the selection and possibly the levels adjustment could be automated using a scripting utility such as AHK above.

SnagIt-04062020 150027_cday.jpg
SnagIt-04062020 150027_cday.jpg (16.89 KiB) Viewed 422 times


mrwul
Posts: 264
Joined: Tue May 25, 2010 7:01 pm

Re: Replace all colours with black, except white

Post by mrwul » Mon Jun 08, 2020 12:58 pm

Thank you both.

I am sorry...

Please note that the number of images to be processes is about 800-900.

I have not been able to manage that within Screenshot Reader.

As for ImageMagick, I believe that is a command line tool(?)
I tried some examples, but I could not get it right.

For one image an instruction may work, but for the next one, it won't.

Instruction: convert test02.jpeg -fill white -fuzz 40% +opaque "#000000" output2.png
SnagIt-08062020 144948.png
Bad luck... :(

cday
XnThusiast
Posts: 2456
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Replace all colours with black, except white

Post by cday » Mon Jun 08, 2020 3:44 pm

mrwul wrote:
Mon Jun 08, 2020 12:58 pm
Please note that the number of images to be processes is about 800-900.
Difficult, but how important is it to find a solution, even if it takes time?

I have not been able to manage that within Screenshot Reader.
Abbyy Screenshot Reader reads the text in my processed image above with no errors... :D

I think resizing the source image to give more pixels with smoothing applied is probably necessary, and the utility would seem to only accept black text, although I haven't tested that specifically.

As for ImageMagick, I believe that is a command line tool(?)
I tried some examples, but I could not get it right.

For one image an instruction may work, but for the next one, it won't.
Yes command line, but if the images you have posted are representative of your actual source images, rather than screenshots for example, I think there is really no possibility of converting them into good quality text on a clean white background. NASA might be able to do it... :wink:

So the only way forward I can see is to use OCR to obtain clean text, and then put that text on a new white canvas; if the need is great enough it should be possible to considerably streamline the process using scripted keyboard shortcuts as above.

Edit:

There is actually another way which realistically might well be quicker: read the text in each source image, and then use a text tool to key it onto a clean white canvas. There are probably various possible sequences, but again many of the required sequences of steps could be assigned to keyboard shortcuts.

mrwul
Posts: 264
Joined: Tue May 25, 2010 7:01 pm

Re: Replace all colours with black, except white

Post by mrwul » Tue Jun 09, 2020 9:59 am

I found 1 / one (maybe unique??) application that can do this.
VideoSubFinder.
It is a 'reasonable' quality and good OCR program can produce a good text file of it.
SnagIt-09062020 115034.png
As said, I have not found any other program that can do the same...

User avatar
XnTriq
Moderator & Librarian
Posts: 5575
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: Replace all colours with black, except white

Post by XnTriq » Tue Jun 09, 2020 1:45 pm

mrwul wrote:
Tue Jun 09, 2020 9:59 am
I found 1 / one (maybe unique??) application that can do this.
VideoSubFinder.
It is a 'reasonable' quality and good OCR program can produce a good text file of it.
Wow, great find :-o
Thanks for sharing, mrwul!

mrwul
Posts: 264
Joined: Tue May 25, 2010 7:01 pm

Re: Replace all colours with black, except white

Post by mrwul » Wed Jun 10, 2020 10:25 am

But please do note the quality.. as you can see it is not perfect.

Good OCR programs (like Abbyy Finereader) can handle almost everything quite correctly.
Because of the reduced quality it may go wrong on specifically the 'full stop' and the 'comma'.
Meaning to say that it may regularly be the case that a comma is detected/seen as a full stop.
This is because of the reduced quality and the tiny stroke below the dot (so as to make it a comma) is gone.
Post editing is necessary then.

I wished nconvert could do the same, but with a better quality (reason for asking here)

(Image>Change Color Depth>Greyscale
+ Image > Adjust > Enhance colours > Contrast : maximum
+ Brightness minus 50 or 80 or so,
then invert)

BUT!
I am not an expert...

Anyway ...
Thanks for all the feedback here.

cday
XnThusiast
Posts: 2456
Joined: Sun Apr 29, 2012 9:45 am
Location: Cheltenham, U.K.

Re: Replace all colours with black, except white

Post by cday » Wed Jun 10, 2020 11:22 am

mrwul wrote:
Wed Jun 10, 2020 10:25 am
Good OCR programs (like Abbyy Finereader) can handle almost everything quite correctly.
Because of the reduced quality it may go wrong on specifically the 'full stop' and the 'comma'.
Meaning to say that it may regularly be the case that a comma is detected/seen as a full stop.
This is because of the reduced quality and the tiny stroke below the dot (so as to make it a comma) is gone.
Post editing is necessary then.
Text quality could probably be significantly improved if the source images were resized 200% or possibly even 400% before processing, that could be done easily as a preliminary batch operation using XnConvert or XnView MP batch convert. Increasing the number of pixels should improve recognition accuracy, although commas could well still be a problem, although possibly less so.

I wished nconvert could do the same, but with a better quality (reason for asking here)
If you are able to use the same settings for all or at least most images, avoiding the need to use any custom settings for each image, NConvert could probably be used if the all operations you need are supported in the help file.

I would consider starting with a crop just large enough to always include the text in the images, assuming the position is reasonably consistent. That should eliminate a large number of unwanted stray pixels.

User avatar
XnTriq
Moderator & Librarian
Posts: 5575
Joined: Sun Sep 25, 2005 3:00 am
Location: Ref Desk

Re: Replace all colours with black, except white

Post by XnTriq » Wed Jun 10, 2020 12:30 pm

Have you considered exporting an XnView slideshow of your images to video and extracting the hard-coded subtitles with one of the following tools?

Post Reply