使用ImageMagick删除图像中除黑色以外的所有颜色? [英] Using ImageMagick to remove all color except black in an image?
问题描述
情况是:我有许多来自扫描的文档图像。我想保留文档的主要内容 - 它是打印为黑色(#000000周围的小范围的颜色)。但是,你知道,文件总是充满颜色:邮票,背景,装饰品,标志...等。
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.
我只想保留TEXTS
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
但结果不是预期的,文本是非常破坏,我不能读。
有人建议我将模糊度提高到70%:
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!
推荐答案
要匹配除黑色之外的所有颜色,您可以使用 + opaque#000000
。
为了包括#000000左右的范围,你可以尝试不同的百分比 fuzz
运算符:
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
使用ImageMagick 6.6.0-1在Windows上
这篇关于使用ImageMagick删除图像中除黑色以外的所有颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!