Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Added projection wrap correction
#! /bin/bash
# Convert Landsat 8 GeoTIFF images into RGB pan-sharpened JPEGs.
#
# Requirements:
# * gdal http://www.mapbox.com/tilemill/docs/guides/gdal/
# * convert (image-magick)
#
# Reference info:
# http://www.mapbox.com/blog/putting-landsat-8-bands-to-work/
# http://www.mapbox.com/tilemill/docs/guides/gdal/
# http://www.mapbox.com/blog/processing-landsat-8/
# http://earthexplorer.usgs.gov/
if [[ -z "$1" ]]; then
echo "Landsat image processing"
echo ""
echo "Converts to 8-bit, merges RGB, pan-sharpens, colour corrects and converts to JPG"
echo "Example: process_landsat LC82010242013198LGN00"
echo ""
exit 0
fi
if [ ! -f ./"$1"_B2.TIF ]; then
echo "File not found!"
exit 0
fi
if [ ! -d "$DIRECTORY" ]; then
mkdir tmp
fi
# Convert 16-bit images into 8-bit and tweak levels
for BAND in {8,4,3,2}; do
docker run -v $(pwd):/data spara/gdal_ef:local gdalwarp -t_srs EPSG:3857 "$1"_B"$BAND".TIF b"$BAND"-projected.tif;
docker run -v $(pwd):/data spara/gdal_ef:local gdal_contrast_stretch -ndv 0 -percentile-range 0.03 .99 b"$BAND"-projected.tif b"$BAND"-8bit.tif;
done
# Merge RGB bands into one image
docker run -v $(pwd):/data spara/gdal_ef:local gdal_merge_simple -in b4-8bit.tif -in b3-8bit.tif -in b2-8bit.tif -out rgb.tif
# Pan-sharpen RGB image
docker run -v $(pwd):/data spara/gdal_ef:local gdal_landsat_pansharp -rgb rgb.tif -lum rgb.tif 0.25 0.23 0.52 -pan b3-8bit.tif -ndv 0 -o pan.tif
# Colour correct and convert to JPG
docker run -v $(pwd):/data spara/gdal_ef:local convert -verbose -channel B -gamma 0.8 -quality 95 pan.tif final-pan-rgb-corrected.jpg
echo "Finished."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment