I often scan handwritten documents to send to colleagues, and need to make corrections to the digital file once it's scanned. (For example, I change mistakes I made on the original document to white.)
I am thinking of some script which can do the following:
Take a color scan image (say a tiff) as input, and make simple corrections automatically based on colored 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 closed circle (with a pen on the actual sheet of paper) around that area. Then I scan the image (or usually many of them). Now I would like the script to erase each of these areas in all of the images so my mistakes disappear in the resulting image.
Any ideas how to realize this in a Linux environment, e.g. with Image Magick?
It looks like Gimp with script-fu could be the way to go it should be powerful enough. Can somebody give me a hint by pointing out the above example would look like in script-fu?
I'm thinking in a solution based on ImageMagick. We would need the following steps:
x
and y
coordinates in the image;We could use the following script based on functions of ImageMagick:
Output all the unique colors in the picture. This will be used to find out which are the RGB components of the target color (command source).
convert <image> -unique-colors -depth 8 txt:- > output.txt
Output 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 by step 1 was red:
grep red coord.txt
Finally, use x
and y
as a seed to floodfill
to replace the circle region by your desired color (command source). In this case, I've used white
to erase the region:
convert <image> -fill white -fuzz 13% \
-draw 'color <x>,<y> floodfill' <image_floodfill_output>
The -fuzz
parameter will avoid that colors which were originally red
and became corrupted due to noise also gets replaced.
This tutorial gives more information about floodfill
function, such as how to replace the edge colors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With