Page 1 of 1

Remove Everything Non Grey or Black

Posted: 2019-11-27T01:39:34-07:00
by randy
Hi,

For days, I have been attempting to cleanup an image of a printed document (writing in black/dark grey) that has been written on (with blue or red pen).

I'd like to erase all the markings to leave only the original text.

So far, I have tried different thresholds of grey to differentiate each pixel (part of text that is black/grey or not part of text) and substituting non text pixels with white.

The results have been underwhelming in terms of how clean the original text looks (fuzzy at times) or how much of the markings have been erased (sometimes they leave marks) and always having to guess the threshold each time is also not ideal.

Does anyone have another idea on this matter?

Basically turn the below picture below into the paper before it was written in with red.
Image

Thank you!

Re: Remove Everything Non Grey or Black

Posted: 2019-11-27T08:07:18-07:00
by snibgo
What version of IM on what platform? I'll assume v7 on Windows BAT.

GIF is a terrible format to use because it can record only 256 different colours.

Many of your "white" or "gray" pixels are actually coloured. This gives a reasonable result. "+write t.png" creates a debugging image, and can be removed.

Code: Select all

%IMG7%magick ^
  Write3key.gif ^
  ( -clone 0 ^
    -fill White -colorize 100 ^
  ) ^
  ( -clone 0 ^
    -colorspace HCL -channel 1 -separate +channel ^
    -threshold 10%% ^
    +write t.png ^
  ) ^
  -alpha off ^
  -compose Over -composite ^
  out.png

Re: Remove Everything Non Grey or Black

Posted: 2019-11-27T18:44:37-07:00
by randy
Thanks so much that worked!