Skip to content

Instantly share code, notes, and snippets.

@rcoup
Last active October 6, 2015 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcoup/3057968 to your computer and use it in GitHub Desktop.
Save rcoup/3057968 to your computer and use it in GitHub Desktop.
Parallel version of GDAL's nearblack tool for stripping black/white borders from images.
#!/bin/bash
USAGE="Runs GDAL nearblack utility over files in a directory tree in parallel.
Usage: $0 SOURCE/ DEST/ [nearblack options]
Recommended/default nearblack options:
-setalpha -white -nb 0 -near 0 -of GTiff -co COMPRESS=DEFLATE -co TILED=YES
See more details on nearblack at: http://www.gdal.org/nearblack.html
Requires GNU Parallel & GDAL >= 1.8. Get Parallel .deb files from:
https://build.opensuse.org/package/show?package=parallel&project=home:tange"
if [ "$#" -lt "2" ]; then
echo "$USAGE"
exit 2
fi
SOURCEPATH=$1
shift
DESTPATH=$1
shift
if [ "$#" == "0" ]; then
NBARGS="-setalpha -white -nb 0 -near 0 -of GTiff -co TILED=YES -co COMPRESS=DEFLATE"
else
NBARGS="$@"
fi
find "$SOURCEPATH" -type f "(" -iname "*.JPG" -o -iname "*.TIF" -o -iname "*.TIFF" ")" -printf "%P\0" | \
parallel -0 --eta -u \
"mkdir -p \"$DESTPATH/{//}\"; nearblack -q -o \"$DESTPATH/{}\" $NBARGS \"$SOURCEPATH{}\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment