Remove Everything Non Grey or Black

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
randy
Posts: 2
Joined: 2019-11-27T01:31:46-07:00
Authentication code: 1152

Remove Everything Non Grey or Black

Post by randy » 2019-11-27T01:39:34-07:00

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!

snibgo
Posts: 12433
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Remove Everything Non Grey or Black

Post by snibgo » 2019-11-27T08:07:18-07:00

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
snibgo's IM pages: im.snibgo.com

randy
Posts: 2
Joined: 2019-11-27T01:31:46-07:00
Authentication code: 1152

Re: Remove Everything Non Grey or Black

Post by randy » 2019-11-27T18:44:37-07:00

Thanks so much that worked!

Post Reply