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

Updates

  1. Converted a multi-page PDF to individual PNG images for processing via this Automator workflow (before discovering that the first convert command above works equally well on multipage PDFs):

    1. Files & Folders > Ask for Finder Items
    2. PDFs > Render PDF Pages as Images
    3. Files & Folders > Rename Finder Items > select Make Sequential from dropdown
    4. Files & Folders > Move Finder Items > select Destination directory
  2. Convert color PDF to black and white

  3. For despeckling PDFs, see 4lex4's ScanTailor Advanced (which "merges the features of the ScanTailor Featured and ScanTailor Enhanced versions, brings new ones and fixes") or this newer fork. macOS instructions and cross-platform guide | 4lex4's 2017 announcement on DIY Book Scanner

/nix | Feb 02, 2018


Subscribe or visit the archives.