2

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:

enter image description here

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?

3
  • Are you sure that the input tiff was not paletted? I would not convert 10000x10000 pixel images into png format but maybe you have some good reason for that. Depending on the use case I would use tiled GeoTIFF with lossless or lossy compression instead.
    – user30184
    Commented Jun 13, 2022 at 13:15
  • Pretty sure, shouldn't gdalinfo indicate a palette, if there is one? Should I give PaletteRemover a try? Commented Jun 13, 2022 at 13:38
  • 1
    Yes, gdalinfo shows ColorInterp=Palette and the color table entries for paletted images. But it seems that you maybe found a solution. Still the "Optimization level" feels somehow similar to ZLEVEL in gdal.org/drivers/raster/png.html and that should not change color interpretation. But you may be right, what FME really does is not documented in details docs.safe.com/fme/html/FME_Desktop_Documentation/….
    – user30184
    Commented Jun 13, 2022 at 14:11

2 Answers 2

2

The reason for this is that I stumbled upon the PNG Optimization Level-parameter which I set to "Level_1_(recommended)" ("recommended" sounds like a good choice at first sight):

enter image description here

Since some of the resulting images remain RGB and some a converted to palette, my working hypothesis is that if the parameter is set to a value >0 FME tries to estimate if a conversion to palette leads to a significant reduction in file size. So, leaving this to "No_optimization" always results in RGB interpretation provided the source is RGB.

2

Your answer is correct (and may I say that it was a very good observation). Setting optimization can result in some changes to the data structure.

In particular, it might result in:

  • Adding a palette (as in your example)
  • Altering a palette (if it has duplicate or unused entries)
  • Reducing bit depth (reducing 16-bit to 8-bit if the data allows it)
  • Reducing colours (an RGB image with only gray pixels becomes grayscale)
  • Removing alpha channel (if all pixels are opaque)

Sometimes reducing colours or palette values can also enable a bit-depth reduction too, so they're not operating in isolation.

I'd guess that most of these could happen at a low level of optimization because they're considered as lossless. That's why level 1 is probably the recommended level. But the default is "no optimization" because we wouldn't want to change your data without your knowledge.

If you think the interface is a bit misleading then let me know and I can ask for changes. Certainly, I'm not sure if "recommended" means "we recommend this more than no optimization" or "we recommend this only if you want optimization".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.