I have a pile of TIFF images (aerial photography) that I want to convert to PNG. Band interpretation of my source TIFF files is allways RGB, cp. gdalinfo:
C:\OSGeo4W>gdalinfo -mm -stats s:\ER-GIS-Daten\Luftbild\2020\Lieferung\14_TrueOrthomosaic_RGB_TIFF_500x500m_5cm\330880.tif
Driver: GTiff/GeoTIFF
Files: s:\ER-GIS-Daten\Luftbild\2020\Lieferung\14_TrueOrthomosaic_RGB_TIFF_500x500m_5cm\330880.tif
s:\ER-GIS-Daten\Luftbild\2020\Lieferung\14_TrueOrthomosaic_RGB_TIFF_500x500m_5cm\330880.tfw
Size is 10000, 10000
Origin = (633000.000000000000000,5488500.000000000000000)
Pixel Size = (0.050000000000000,-0.050000000000000)
Metadata:
TIFFTAG_DATETIME=2020:05:19 13:57:41
TIFFTAG_IMAGEDESCRIPTION=OrthoVistaProcessing ImageWriter
TIFFTAG_RESOLUTIONUNIT=2 (pixels/inch)
TIFFTAG_SOFTWARE=Adobe Photoshop 21.1 (Windows)
TIFFTAG_XRESOLUTION=72
TIFFTAG_YRESOLUTION=72
Image Structure Metadata:
INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left ( 633000.000, 5488500.000)
Lower Left ( 633000.000, 5488000.000)
Upper Right ( 633500.000, 5488500.000)
Lower Right ( 633500.000, 5488000.000)
Center ( 633250.000, 5488250.000)
Band 1 Block=10000x1 Type=Byte, ColorInterp=Red
Computed Min/Max=0.000,255.000
Minimum=0.000, Maximum=255.000, Mean=255.000, StdDev=0.208
Metadata:
STATISTICS_MAXIMUM=255
STATISTICS_MEAN=254.99975402
STATISTICS_MINIMUM=0
STATISTICS_STDDEV=0.20842394174816
STATISTICS_VALID_PERCENT=100
Band 2 Block=10000x1 Type=Byte, ColorInterp=Green
Computed Min/Max=0.000,255.000
Minimum=0.000, Maximum=255.000, Mean=255.000, StdDev=0.214
Metadata:
STATISTICS_MAXIMUM=255
STATISTICS_MEAN=254.99974602
STATISTICS_MINIMUM=0
STATISTICS_STDDEV=0.21399129770661
STATISTICS_VALID_PERCENT=100
Band 3 Block=10000x1 Type=Byte, ColorInterp=Blue
Computed Min/Max=0.000,255.000
Minimum=0.000, Maximum=255.000, Mean=255.000, StdDev=0.298
Metadata:
STATISTICS_MAXIMUM=255
STATISTICS_MEAN=254.99963607
STATISTICS_MINIMUM=0
STATISTICS_STDDEV=0.29783649466604
STATISTICS_VALID_PERCENT=100
In some (not all) of the resulting PNG's however, band interpretation turns from source rgb to palette, gdalinfo for the resulting PNG file associated with the above example:
Driver: PNG/Portable Network Graphics
Files: Q:/Luftbilder/2020/0.05/330880.png
Q:/Luftbilder/2020/0.05/330880.wld
Size is 10000, 10000
Origin = (633000.000000000000000,5488500.000000000000000)
Pixel Size = (0.050000000000000,-0.050000000000000)
Corner Coordinates:
Upper Left ( 633000.000, 5488500.000)
Lower Left ( 633000.000, 5488000.000)
Upper Right ( 633500.000, 5488500.000)
Lower Right ( 633500.000, 5488000.000)
Center ( 633250.000, 5488250.000)
Band 1 Block=10000x1 Type=Byte, ColorInterp=Palette
Computed Min/Max=0.000,125.000
Minimum=0.000, Maximum=125.000, Mean=125.000, StdDev=0.101
Metadata:
STATISTICS_MAXIMUM=125
STATISTICS_MEAN=124.99989161
STATISTICS_MINIMUM=0
STATISTICS_STDDEV=0.10079413798236
STATISTICS_VALID_PERCENT=100
Color Table (RGB with 126 entries)
0: 0,0,0,255
1: 0,2,0,255
2: 2,4,0,255
3: 3,4,0,255
4: 10,7,0,255
5: 21,22,0,255
6: 52,50,0,255
7: 61,53,0,255
8: 67,62,0,255
9: 71,66,0,255
10: 76,68,0,255
11: 77,71,0,255
12: 81,78,0,255
13: 82,70,0,255
14: 82,78,0,255
15: 83,71,0,255
16: 84,68,0,255
17: 85,79,0,255
18: 87,77,0,255
[...]
The workspace for this is simplest one can think of, GeoTIFF reader, PNG writer:
Why this (randomly) reinterpretation of the bands and adding a palette and how can I overcome this behavior and force PNG writer to allways use RGB interpretation when source data is like this?