[gdal-dev] Unusual RGB Tiff files with misleading PhotometricInterpretation: valid or not?

Mikael Rittri Mikael.Rittri at carmenta.com
Sat Nov 17 11:51:27 PST 2018


Thanks for the excellent and fast information, Even and Andrew. I think I have learned all I need to know,
for now. Much obliged.

ER>  ... but of course, readers are not expected to interpret such 3-channel files as being RGB.

That's what I thought, but I am glad that you confirm it. I was confused when both ArcMap and QGIS 
chose a default display that assumed some kind of RGB.  I suppose they have some built-in rule of thumb, 
saying that three channels declared as Gray/Undefined/Undefined are most likely to be a mis-tagged RGB file.

By the way, I also had got the impression that MinIsBlack would refer to all channels, but I suppose the libtiff
behaviour must be correct - that makes more sense. One of my files did have 2 values for Extra Samples, but 
not the other.  Weird. 

The default visualization for a Gray/Undefined/Undefined file in Carmenta Engine, when using our GdalDataSet
class (based on you-know-what), is to just show the first channel as a grayscale. I think this is faithful to the
declared Photometric Interpretation, but for these mis-tagged files I noticed a risk: a Red channel displayed
as grayscale can show enough of the map features that you don't notice something is wrong - you think you
are seeing a grayscale map correctly. If the brightness contrasts between foreground and background are
strong, it looks pretty good. But if you are really unlucky, I guess there could be a text "Danger! Minefield!"
that is colored so that it becomes invisible when only showing the Red channel. 

ER> There are MinSampleValue and MaxSampleValue tags in the TIFF spec, but those
ER> are not really used by GDAL and are just reported as metadata.

OK, but for the record, I checked them in the TIFF specification, and I think you misremember the purpose
of these tags. GDAL seems to be doing the right thing already, since they are supposed to give the min and
max of the range of values that occur in the file - they don't give the representations of min and max intensity. 
They are not supposed to alter the display, but maybe some GIS systems use them for non-standard contrast
enhancement or something.

The TIFF specification does seem to say that for RGB, the min and max intensities are always 0 and 255 for 8-bit
data, and 0 and 65535 for 16-bit data.  I think I finally figured out how the data provider documented that they
used 255 for the max intensity in their 16-bit data: they had a Raster Attribute Table in a .tif.aux.xml file, where
channel values in the range 0 to 255 had an attribute named Contrast of type Double, with the value b/255 for
each value b. Now that's unusual, I think - I have never seen anything like this before.

ACA> Sounds like different default gamma correction values.

That may be a useful clue. I don't know much about gamma correction but I think it may be a part of the problem,
but perhaps not the main one.

Kind regards,

Mikael Rittri
Carmenta Geospatial Technologies
http://www.carmenta.com

________________________________________
From: Even Rouault [even.rouault at spatialys.com]
Sent: Thursday, November 15, 2018 9:20 PM
To: gdal-dev at lists.osgeo.org
Cc: Mikael Rittri
Subject: Re: [gdal-dev] Unusual RGB Tiff files with misleading PhotometricInterpretation: valid or not?

Mikael,

> 1.  If an RGB Tiff file doesn't have PhotometricInterpretation = RGB, can it
> really be claimed that the file adheres to the Tiff standard, or is it
> corrupt?

If it has 2 values for ExtraSamples, then I believe is technically legal (the
TIFF spec is not really clear but libtiff interprets PhotometricInterpretation
= MinIsBlack as meaning one nominal channel, all the other ones being extra
samples), but of course, readers are not expected to interpret such 3-channel
files as being RGB.

> 2.  If the min and max intensities are not the same as the min and max
> representable numbers for the integer type, then how are they specified in
> Tiff?

There are MinSampleValue and MaxSampleValue tags in the TIFF spec, but those
are not really used by GDAL and are just reported as metadata.

$ cp byte.tif test.tif
$ tiffset -s MinSampleValue 1 0 test.tif
$ tiffset -s MaxSampleValue 1 255 test.tif
$ gdalinfo test.tif
[...]
Metadata:
  AREA_OR_POINT=Area
  TIFFTAG_MAXSAMPLEVALUE=255
  TIFFTAG_MINSAMPLEVALUE=0

Even

--
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list