[gdal-dev] Will gdal try to write these two tags when creating tif file?
Rahkonen Jukka
jukka.rahkonen at maanmittauslaitos.fi
Mon Nov 25 00:07:18 PST 2024
Hi,
I had a try by creating a 6-bit COG
gdal_translate -of cog -co nbits=6 P4433H.tif 6bit.tif
tiffinfo shows:
TIFF Directory at offset 0xc0 (192)
Image Width: 12000 Image Length: 12000
Tile Width: 512 Tile Length: 512
Resolution: 0.393677, 0.393677 pixels/cm
Bits/Sample: 6
but the MinSampleValue and MaxSampleValue tags are not set. In https://www.itu.int/itudoc/itu-t/com16/tiff-fx/docs/tiff6.pdf MaxSampleValue is defined this way:
MaxSampleValue The maximum component value used. Tag = 281 (119.H) Type = SHORT N = SamplesPerPixel This field is not to be used to affect the visual appearance of an image when it is displayed or printed. Nor should this field affect the interpretation of any other field; it is used only for statistical purposes. Default is 2**(BitsPerSample) - 1
Thus, the MaxSampleValue in the test image is 63. The default for MinSampleValue is 0. The values may not tell the min/max values of the image data but fortunately
GDAL has its own way for saving the image statistics with more details. Image statistics are copied if they exist in the source image, but they are not computed automatically. The gdal_translate option "-stats" forces the computation of statistics https://gdal.org/en/latest/programs/gdal_translate.html#cmdoption-gdal_translate-stats. As a result a TIFF or COG file will have tags
GDAL Metadata: <GDALMetadata>
<Item name="STATISTICS_APPROXIMATE" sample="0">YES</Item>
<Item name="STATISTICS_MAXIMUM" sample="0">182</Item>
<Item name="STATISTICS_MEAN" sample="0">64.982910819375</Item>
<Item name="STATISTICS_MINIMUM" sample="0">18</Item>
<Item name="STATISTICS_STDDEV" sample="0">19.488070835298</Item>
<Item name="STATISTICS_VALID_PERCENT" sample="0">100</Item>
<Item name="STATISTICS_APPROXIMATE" sample="1">YES</Item>
<Item name="STATISTICS_MAXIMUM" sample="1">179</Item>
<Item name="STATISTICS_MEAN" sample="1">68.324411498416</Item>
<Item name="STATISTICS_MINIMUM" sample="1">17</Item>
<Item name="STATISTICS_STDDEV" sample="1">19.764307166181</Item>
<Item name="STATISTICS_VALID_PERCENT" sample="1">100</Item>
<Item name="STATISTICS_APPROXIMATE" sample="2">YES</Item>
<Item name="STATISTICS_MAXIMUM" sample="2">164</Item>
<Item name="STATISTICS_MEAN" sample="2">63.550390448167</Item>
<Item name="STATISTICS_MINIMUM" sample="2">13</Item>
<Item name="STATISTICS_STDDEV" sample="2">16.774943130374</Item>
<Item name="STATISTICS_VALID_PERCENT" sample="2">100</Item>
</GDALMetadata>
All GDAL based programs can access these tags and know their meaning. I think that you should also make your GeoTIFF/COG renderer to read the GDALMetadata instead of the baseline TIFF tags MinSampleValue and MaxSampleValue.
-Jukka Rahkonen-
Lähettäjä: gdal-dev <gdal-dev-bounces at lists.osgeo.org> Puolesta shark shark via gdal-dev
Lähetetty: maanantai 25. marraskuuta 2024 5.05
Vastaanottaja: gdal-dev at lists.osgeo.org
Aihe: [gdal-dev] Will gdal try to write these two tags when creating tif file?
Hi! Have a good day :D
I'm working on a GeoTIFF/COG renderer and wondering if GDAL automatically writes the minsamplevalue and maxsamplevalue tags when creating a TIFF file, especially for large files.
I just made a cog with goal and I didn't find these tags. And I didn't find a guarantee about these tagsin gdal doc.
Thanks for your help!
Best, Lucas.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20241125/5c7c7d98/attachment-0001.htm>
More information about the gdal-dev
mailing list