Last active
October 6, 2015 21:48
-
-
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.
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
#!/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