tinyapps.org / blog

Remove all color but black from an image #

Background removal apps and web-based services don't do well with noisy images like this one of sheet music on thin parchment paper which has text from the next page bleeding through:

Image of sheet music before removing background

However, ImageMagick works, well... magic: $ convert in.png -fill white -fuzz 80% +opaque "#000000" out.png

Image of sheet music after removing background

If the results aren't satisfactory, try tweaking the fuzz value (e.g., 20%). For multiple images, use a for loop: $ for i in *.png; do convert "$i" -fill white -fuzz 20% +opaque "#000000" "$i-out.png"; done

/nix | Feb 02, 2018

Subscribe or visit the archives