Using ImageMagick to remove all color except black in an image?

colors, imagemagick

Solution

To match all colors except black you can use `+opaque "#000000"`.

In order to include a little range around #000000 you can try different percentages with the `fuzz` operator:

convert input.png -fill white -fuzz 10% +opaque "#000000" result.png

Tested with ImageMagick 6.6.0-1 on Windows

Problem

The situation is : I have many images of documents from scanning. I want to keep the document's main content - which is printed in color black (a small range of colors around #000000). But, you know, the documents are always full of colors : stamp, background, decorations, logos...etc. I just want to keep the TEXTS ONLY which were printed in the color black. I've tried with ImageMagick and this command so far: ``` convert X.png -matte (+clone -fuzz 20% -transparent "#000000") -compose DstOut -composite X1.png ``` But the result was not as expected , the text was very damaged that I cannot read. Someone suggested me to increase the fuzz to 70%: ``` convert X.png -matte (+clone -fuzz 70% -transparent "#000000") -compose DstOut -composite X1.png ``` Then the text appeared to be more readable, but the other colors kept remaining too. Can you please show me a better solution for my situation? Every suggestion would be highly appreciated!

Original source