OTB does not handle tif with NBITS=1 properly
Mantis Issue 1079, reported by mgrizonnet, assigned to mgrizonnet, created: 2015-10-06
Tif format allows to store image on arbitrary number of bands less than 8 bits (1 to 7): http://www.gdal.org/frmt_gtiff.html (The apparent pixel is 'Byte')
You can generate tif coded on 1 bit using OTB and extended file (?&gdal:co:NBITS=1)
GDALImageIO does not read it properly as it interprets the image as a 4 bands image with max value equal to 255 (and not 1).
One possible reason is that OTB is perhaps interpreting color table information available in the input image.
gdalinfo -stats input.tif
Size is 1, 2 Coordinate System is `' Origin = (-0.500000000000000,-0.500000000000000) Pixel Size = (1.000000000000000,1.000000000000000) Image Structure Metadata: COMPRESSION=DEFLATE INTERLEAVE=BAND Corner Coordinates: Upper Left ( -0.5000000, -0.5000000) Lower Left ( -0.5000000, 1.5000000) Upper Right ( 0.5000000, -0.5000000) Lower Right ( 0.5000000, 1.5000000) Center ( 0.0000000, 0.5000000) Band 1 Block=1x2 Type=Byte, ColorInterp=Palette Min=0.000 Max=1.000 Minimum=0.000, Maximum=1.000, Mean=0.500, StdDev=0.500 Metadata: STATISTICS_MAXIMUM=1 STATISTICS_MEAN=0.5 STATISTICS_MINIMUM=0 STATISTICS_STDDEV=0.5 Image Structure Metadata: NBITS=1 Color Table (RGB with 2 entries) 0: 0,0,0,255 1: 255,255,255,255
1444146848 - gpaseroI don't think this bug is caused by the NBITS=1. As stated in GDAL GeoTIFF documentation, when NBTIS=1..7, the apparent pixel type is Byte, so in otbGDALImageIO.cxx, it should be seen as any other Byte image. The explanation of the color table is more likely.
1444231652 - grizonnetmYou're right the cause is the color table. GDAL automatically create a palette in this case (ColorInterp=Palette).
Are we interpreting this info correctly?
QGIS also recognize the input image type as Palette but gives the "right" value when I access pixel info (0 and 1 in this case)
I've attached the image (2 pixels)
1444652737 - gpaseroI agree, GDAL automatically set a palette for color interpretation. In OTB, when a palette is available and pixel type is Byte, the image is automatically read as a color image (using the palette). Perhaps this behaviour should be restricted. Palette could be activated using an extended filename ?
1444998225 - grizonnetmOTB should be able to access both