Is there a way to make a script that automatically corrects scanned documents?

I often review handwritten documents to send to colleagues, and you need to make corrections to the digital file after scanning it. (For example, I am changing the errors that I made in the original document to white.)

I am thinking of some script that can do the following:

Take an image with color scanning (say, tiff) as an input signal and make simple corrections automatically based on color corrections in the image.

For example, take the simplest case: I write only black on white. There is an area where I made mistakes, so I draw a red vicious circle (with a pen on a piece of paper) around this area. Then I look at the image (or, as a rule, many of them). Now, I would like the script to delete each of these areas in all images so that my errors disappear in the resulting image.

Any ideas how to implement this in a Linux environment, for example. with Image Magick?


It seems that Gimp with script -fu might be the way to go, it should be powerful enough. Can someone give me a hint indicating that the above example will look like in script-fu?

+7
source share
2 answers

I am thinking of a solution based on ImageMagick. We will need the following steps:

  • Find the color used to draw in the scanned document (now it is called the target color );
  • Find the x and y coordinates in the image;
  • Pass this position as a seed for the Flood Fill algorithm.

We could use the following script based on ImageMagick functions:

  • Display all unique colors on the screen. This will be used to find out which RGB components are the target color ( command source ).

     convert <image> -unique-colors -depth 8 txt:- > output.txt 
  • Print the coordinates of each color in a text file:

     convert <image> txt:- > coord.txt 
  • Find the x and y coordinates of the target color ( command source ). Suppose the target color obtained in step 1 was red:

     grep red coord.txt 
  • Finally, use x and y as the seed for the floodfill to replace the circle area with your desired color ( command source ). In this case, I used white to remove the area:

     convert <image> -fill white -fuzz 13% \ -draw 'color <x>,<y> floodfill' <image_floodfill_output> 

The -fuzz avoids the fact that colors that were originally red and that were damaged due to noise are also replaced.

This guide provides more information about floodfill , such as how to replace the colors of edges.

+2
source

I would suggest looking at a scanning scanner (perhaps a 3100 scan). There are several things that related software can do that can be useful.

You may find that any software / script you find will not work as you would like. It seems that many of these changes are things that you need to see with the human eye. Perhaps you could hire a personal assistant to make these corrections for you. :)

0
source

All Articles