Created
January 19, 2017 16:04
-
-
Save peterjurkovic/03d894c33d2b263b8f66366457769fef to your computer and use it in GitHub Desktop.
http://superuser.com/questions/693339/batch-processing-images-of-documents-to-look-like-a-fax/708256
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# -*- mode: sh; coding: us-ascii-unix -*- | |
source libstacktrace || true | |
set -e -u -E | |
MANUAL=" | |
Usage: $0 INFILE OUTFILE | |
Takes a document scan INFILE (an image) and produces a monochromatized | |
output file version. | |
" | |
if [[ "${1:-}" = "-?" ]] || [[ "${1:-}" = "-h" ]] || [[ "${1:-}" = "--help" ]]; then | |
echo "$MANUAL" | |
exit 0 | |
fi | |
BLURRADIUS="20" | |
INFILE="$(readlink -m "$1")" | |
OUTFILE="$(readlink -m "$2")" | |
TMPDIR="$(mktemp -d)" | |
cd "$TMPDIR" | |
convert "$INFILE" -colorspace Gray 01.png | |
convert 01.png -blur "${BLURRADIUS}x${BLURRADIUS}" 02.tif | |
convert 01.png 02.tif -compose Divide_Src -composite 03.tif | |
convert 03.tif -threshold 90% -type bilevel -compress group4 "$OUTFILE" | |
rm 01.png 02.tif 03.tif | |
rmdir "$TMPDIR" | |
# for file in *.jpg; do ./imagemagick-scan-to-mono.sh $file rotated-$file; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment