-
-
Save jqtrde/4ef32d4c0a3c3edd89c4 to your computer and use it in GitHub Desktop.
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
####################################################################### | |
###BASH FOR PROCESSING LANDSAT 8 (8-BIT CONVERSION NEEDED AND INCLUDED) | |
######################################################################## | |
###MAKE SURE IMAGERY ZIP FILE IS IN L8_IMAGERY FOLDER ON DESKTOP | |
###THIS SPECIFIC COLOR TWEAKING WAS DESIGNED FOR BAIJI IRAQ AND THEREFORE | |
###WILL BEST FIT DESERT REGIONS! | |
Folder="Baiji_Jun18" | |
#establish an id variable | |
id="LC81690362014169LGN00" | |
cd | |
### Assign directory where compressed landsat package is located | |
cd Desktop/L8_IMAGERY | |
### Make a new directory where landsat files can be unpacked and stored | |
mkdir $Folder | |
### unzip landsat package into the newly made LV_IMAGERY directory | |
tar xvzf $id.tar.gz -C $Folder | |
### Assign working directory to new LV_IMAGERY directory | |
cd $Folder | |
### Make new RESULTS directory for processing outputs | |
mkdir RESULTS | |
### Set 'for' loop to assign Web Mercator (the tilemill/mapbox/webmapping standard SRS) projection to all bands in list and output files as tifs | |
for BAND in {7,5,4,3,2}; do | |
gdalwarp -t_srs EPSG:3857 $id"_B"$BAND.TIF RESULTS/$BAND-projected.tif; | |
done | |
### Sets new working directory to new RESULTS directory | |
cd RESULTS | |
######################### | |
#CREATE COMPOSITES | |
######################### | |
### Combines 3 bands into new true-color (RGB) composite and saves as a tif | |
convert -combine {4,3,2}-projected.tif RGB.tif | |
### Combines 3 bands into new false-color (753) composite and saves as a tif | |
convert -combine {7,5,3}-projected.tif 753.tif | |
convert -sigmoidal-contrast 50x19.5% RGB.tif RGB-corrected_19_5.tif | |
######################### | |
#TWEAK RGB | |
######################### | |
convert -channel R -gamma 0.9 -channel B -gamma 1.2 -channel G -gamma 1.5 RGB-corrected_19_5.tif RGB-corrected2.tif | |
convert -auto-gamma -modulate 80,110 RGB-corrected2.tif RGB-corrected_AUTOGAMMA.tif | |
######################### | |
#TWEAK CONTRAST 753 | |
######################### | |
convert -sigmoidal-contrast 50x32% 753.tif 753-corrected_32.tif #selected as best for moving forward | |
######################### | |
#TWEAK COLOR 753 | |
######################### | |
convert -channel G -gamma 0.80 -channel R -gamma 1.1 753-corrected_32.tif 753-corrected_32_colorRG.tif | |
######################### | |
#CONVERT FROM 16 TO 8 BIT | |
######################### | |
### Convert tif from 16-bit to 8-bit | |
convert -depth 8 753-corrected_32_colorRG.tif 753-corrected-8bit.tif | |
convert -depth 8 RGB-corrected_AUTOGAMMA.tif RGB-corrected-8bit.tif | |
######################### | |
#DOWNSAMPLING | |
######################### | |
#use a cubic downsampling method to add overviews | |
#(other interpolation methods are available) | |
gdaladdo -r cubic 753-corrected-8bit.tif 2 4 8 10 12 | |
gdaladdo -r cubic RGB-corrected-8bit.tif 2 4 8 10 12 | |
######################### | |
#REASSIGN SPATIAL REF | |
######################### | |
### Creation of .tfw and rename it to fit new file (TFW contains georeference info for raster map images) | |
listgeo -tfw 4-projected.tif | |
mv 4-projected.tfw 753-corrected-8bit.tfw | |
### Creation of .tfw and rename it to fit new file (TFW contains georeference info for raster map images) | |
listgeo -tfw 3-projected.tif | |
mv 3-projected.tfw RGB-corrected-8bit.tfw | |
### Reprojection of final file to Web-Mercator | |
gdal_edit.py -a_srs EPSG:3857 753-corrected-8bit.tif | |
### Reprojection of final file to Web-Mercator | |
gdal_edit.py -a_srs EPSG:3857 RGB-corrected-8bit.tif | |
######################### | |
#FINAL NAMING | |
######################### | |
### Renaming of final file to something more defining of the final product | |
mv 753-corrected-8bit.tif 753_$Folder.tif | |
### Renaming of final file to something more defining of the final product | |
mv RGB-corrected-8bit.tif RGB_$Folder.tif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment