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

后端 未结 3 1801
Happy的楠姐
Happy的楠姐 2020-12-14 12:14

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 arou

相关标签:
3条回答
  • 2020-12-14 12:49

    I stumbled upon this question while looking for an answer to this question. I found a couple imagemagick forum posts that helped. Here is what I came up with:

    convert input.gif -matte \( +clone -fuzz 1 -transparent black \) -compose DstOut -composite ~/Desktop/output.png
    

    Forum post: ImageMagick: Removing all but one color

    0 讨论(0)
  • 2020-12-14 12:56

    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

    0 讨论(0)
  • 2020-12-14 13:02

    You should try the level command:

    convert test.png -level 25%,75% test_level.png
    
    0 讨论(0)
提交回复
热议问题