Good way to remove grey background from (scanned) pictures?

For everything that's not in any way related to PureBasic. General chat etc...
Little John
Addict
Addict
Posts: 4794
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Good way to remove grey background from (scanned) pictures?

Post by Little John »

Hi all,

in scanned pictures (e.g. pages from textbooks) sometimes there is a gray background.
Or in the following example, the only photo-copy I had available for scanning was of poor quality:

Image

Especially for the picture above, I didn't find a way to improve the quality, i.e. make the text in the boxes good readable.
I tried with Faststone Image Viewer and Paint.net, using all functions that I found for changing the contrast etc., but to no avail.

Does someone of you know a way to make the text better readable?
Maybe a special (free) program, or perhaps a clever algorithm written in PureBasic?
I think an appropriate algorithm based on wavelets might do the trick, but currently I don't know enough about wavelets for writeing such a program myself.

Thanks in advance for any suggestions that point into the desired direction.
User avatar
TI-994A
Addict
Addict
Posts: 2741
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Good way to remove grey background from (scanned) pictur

Post by TI-994A »

Hi Little John. If the original is already of such quality, like the example you posted, I'm not sure.

But if you're scanning in from textbooks, as you said, increasing the brightness and decreasing the contrast settings on the scanner itself might improve the results. It usually works for me when scanning documents with coloured backgrounds.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
User avatar
Michael Vogel
Addict
Addict
Posts: 2812
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Good way to remove grey background from (scanned) pictur

Post by Michael Vogel »

I tried some effect functions in paintshop pro, but the results are not that good...

Remove Artefacts
Image

Lighter/Darker
Image
Little John
Addict
Addict
Posts: 4794
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Good way to remove grey background from (scanned) pictur

Post by Little John »

Michael Vogel wrote:I tried some effect functions in paintshop pro, but the results are not that good...
Many thanks for trying!
Your results look pretty much like the results that I got ... not really satisfying.
I hope that there is a better solution.
Thanks again.
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Re: Good way to remove grey background from (scanned) pictur

Post by Kukulkan »

I would try to use simple curves to set a threshold for the WhitePoint. Should not be that hard to implement but I believe you need to find a method to determine the right threshold value.

But in my experience, it is mostly worth to try to get better scans. Some better scanners also have image enhancement algorithms who do a great job on such images directly during scanning. Eg, try to find some OCR enhancements in your scanner software.

Image
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Good way to remove grey background from (scanned) pictur

Post by IdeasVacuum »

If the example is representative, then PB could maybe help reverse-engineer the diagram to re-draw it.

1) Use Point() to find all the jet-black pixels. There will be a lot of "noise" but the text could be good enough to
2) Use Character Recognition to store the text as text. (OCR).
3) Use Point() to find all the background pixels (white?). Plot them onto a canvas that is pre-coloured with the colour of the diagram boxes.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
sancho2
User
User
Posts: 44
Joined: Wed Apr 15, 2015 5:14 am

Re: Good way to remove grey background from (scanned) pictur

Post by sancho2 »

I think a decent smart phone camera will do a better job of "scanning" the photocopy you had. If you have to scan then a color scanner will be better than a black and white, as it won't try to shade non-white areas.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Good way to remove grey background from (scanned) pictur

Post by davido »

@Little John,
Perhaps there is a suitable algorithm in OpenCV?
DE AA EB
Little John
Addict
Addict
Posts: 4794
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Good way to remove grey background from (scanned) pictur

Post by Little John »

Kukulkan wrote:I would try to use simple curves to set a threshold for the WhitePoint. Should not be that hard to implement but I believe you need to find a method to determine the right threshold value.
Thank you for looking into his issue, and for posting your result.
I have done something similar. The result is even a little better, when this method is applied separately to light and dark areas of the picture.
I'm now looking for a software or algorithm, that produces better results, by separating singnal from noise.
Kukulkan wrote:But in my experience, it is mostly worth to try to get better scans.
I agree. However, my main problem is currently that I have several poor black/white photo-copies, and the best scan that I can get is almost exactly like the photo-copy, i.e. it is poor as well, like the example that I posted.
Little John
Addict
Addict
Posts: 4794
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Good way to remove grey background from (scanned) pictur

Post by Little John »

IdeasVacuum wrote:If the example is representative, then PB could maybe help reverse-engineer the diagram to re-draw it.
Thanks for the suggestion.
Unfortunately, the example is not exactly representative, i.e. the signal in the pictures is not always text.
Little John
Addict
Addict
Posts: 4794
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Good way to remove grey background from (scanned) pictur

Post by Little John »

davido wrote:@Little John,
Perhaps there is a suitable algorithm in OpenCV?
Davido, many thanks for this suggestion!
I've also thought about OpenCV, but unfortunately I don't know much about it.
Something like this seems not to be covered by JHPJHP's "PureBasic Interface to OpenCV".

However, now I found an interesting article, which seems to point into the right direction.
Thanks again!
Post Reply