Thursday, 14 May 2015

gdal - How can I use gdal_retile on RGBI (4 band) GeoTIFFs while preserving band information?


I want to retile large GeoTIFFs with 4 bands: R = Red, G = Green, B = Blue, NIR = Near Infra Read; in short "RGBI" if I understand correctly.


gdalinfo on the input file prints as band information:


Band 1 Block=512x512 Type=Byte, ColorInterp=Red
Band 2 Block=512x512 Type=Byte, ColorInterp=Green
Band 3 Block=512x512 Type=Byte, ColorInterp=Blue
Band 4 Block=512x512 Type=Byte, ColorInterp=Undefined

After running gdal_retile.py, the fourth (NIR) channel is converted to an Alpha-Channel. gdalinfo on the output file prints as band information:


Band 1 Block=1024x2 Type=Byte, ColorInterp=Red

Overviews: 512x512, 256x256, 128x128
Mask Flags: PER_DATASET ALPHA
Overviews of mask band: 512x512, 256x256, 128x128
Band 2 Block=1024x2 Type=Byte, ColorInterp=Green
Overviews: 512x512, 256x256, 128x128
Mask Flags: PER_DATASET ALPHA
Overviews of mask band: 512x512, 256x256, 128x128
Band 3 Block=1024x2 Type=Byte, ColorInterp=Blue
Overviews: 512x512, 256x256, 128x128
Mask Flags: PER_DATASET ALPHA

Overviews of mask band: 512x512, 256x256, 128x128
Band 4 Block=1024x2 Type=Byte, ColorInterp=Alpha
Overviews: 512x512, 256x256, 128x128

The conversion of the Infrared-band into an Alpha mask is causing me troubles. Can I prevent this behavior (of gdal_retile.py)? Or alternatively: Can I reverse the effect by changing the Alpha band back to an "Undefined" band?


The gdal_retile.py parameters I ran with (on GDAL version 1.11) are:


gdal_retile.py 
-s_srs EPSG:31464 [georeference]
-ps 1024 1024 [pixel width/height)
-tileIndex "tileIndex.shp"

-csv "tileGeoRef.csv"
-targetDir "...\outputfolder"
"...\inputfile.tif"

Purpose of the operation is to cut the large GeoTIFF into small 1024x1024 images.



Answer



I found an answer for exactly this problem in the [gdal-dev] Mailing list: To avoid the fourth band being interpreted as ALPHA channel, the corresponding option ALPHA=NO can be specified for the GeoTIFF driver. To preserve the RGB order, apparently there is the option PHOTOMETRIC=RGB - for more read the mailing list. In my case the ALPHA=NO option was enough.


When calling the script via command-line, use the -co "OPTION-NAME=VALUE" parameter (see doc) to specify options.


My full command was:


gdal_retile.py 


-co "ALPHA=NO"

-s_srs EPSG:31464 [georeference]
-ps 1024 1024 [pixel width/height)
-tileIndex "tileIndex.shp"
-csv "tileGeoRef.csv"
-targetDir "...\outputfolder"
"...\inputfile.tif"

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...