1

Edit: I posted this question on the Computer Graphics site here per suggestion

I have a bunch of scanned document images and in each image there is a variance in background colour (sometimes a wide variance).

I want to adjust all image pixels such that they are 'normalized' towards the pixel colour mean. To put it another way, I want to adjust all pixel colour values (or grayscale) so that the background colour (e.g. the 'white page') loses the colour gradients and variation and instead becomes as close as possible to white (or white).

I have been looking into colour gradients, vectorization and various filters, thresh-holding and blurring techniques, but I can't quite work out how to do what I see in my head.

Take the following example image: (ignore my red annotation)

enter image description here

I want to find out what the overall mean colour is for all pixels, then for each pixel reduce or increase it towards the mean value to create a more 'flat' image. The reason I want to do that is because I believe it will improve the next step, which is to detect contours and edges for the purpose of text detection (and ultimately better OCR results).

So in the above example, the goal is to effectively remove the gray diagonal lines, but leave the text. I think there might be a way to automatically determine a threshold value (or have a dynamic threshold) but I am not sure exactly how to do that.

Here is another example image:

enter image description here

The goal for this second image would be to effectively remove the target logo and most of the other background 'document colour mess' picked up by the scanner, as per the annotation.

The goal is to improve text block detection to then improve OCR accuracy.

Edit: This process has to be automated because doing it manually would essentially defeat the purpose and I may as well go back to manual data entry by eyeballing every document (ugh!). This is why I have been trying to use OpenCV in Python. The second point is that since every image is different I need to be able to determine the threshold (for final binarization prior to OCR) automatically, which is kind of what I mean by 'normalization' above.

1
  • Asking a graphic designer to automate things is like asking a lawyer to build a factory. I mean its possible they know how to do it but somewhat unlikely. But yeah in this case theres no real need to analyze the images just drop pixels below certain value.
    – joojaa
    Nov 2, 2023 at 5:02

2 Answers 2

0

Photoshop's 'Threshold' is good for that kind of task - though I'm not sure how you could automate it.

enter image description here enter image description here

Having said that, Readiris can do it too - & no doubt other OCR software.

enter image description here

0

A levels adjustment would likely be the best option for you. This can be done in software such as Photoshop (not free) or GIMP (free).

In Photoshop do Image > Adjustments > Levels

In GIMP do Colors > Levels

Then just move the right side highlight handle towards the centre of the historgram until the grey disappears. If the text becomes too light, you can then move the middle handle closer to the right to darken it up a bit.

This example is in Photoshop, but it's very similar in GIMP

enter image description here

5
  • Thank you, but I realize I did not clearly specify that I need to automate this task, hence the reason I have been playing around with OpenCV in Python. I will update my question to include that.
    – skeetastax
    Nov 1, 2023 at 10:11
  • @skeetastax I don't know if it would be possible to automate it fully in Photoshop or GIMP or any software. That would require some kind of analysis of the whole image, and some way for the software to know what you want, some kind of AI perhaps? Sorry. This seems outside the scope of Graphic Design, rather an image analysis problem that would involve coding (which is off topic here).
    – Billy Kerr
    Nov 1, 2023 at 10:14
  • Hmmm...yeah, it is kind of a coding question...but it is very specific to image (pixel data) processing and I thought that 'image geeks' would know details on filtering and thresholding techniques and algorithms, and other image processing tricks, hence the reason for asking here (though when I think about it, there would be an audio analogue...pardon the pun :P)
    – skeetastax
    Nov 1, 2023 at 10:22
  • @skeetastax Maybe try Computer Graphics Stack Exchange.
    – Billy Kerr
    Nov 1, 2023 at 10:24
  • Oh, I didn't know there was such a site...will do.
    – skeetastax
    Nov 1, 2023 at 10:42

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .