Unsigned integer TIFF containing negative NoData value

arcgis-desktopbit depthraster

Background:

At 10.8.1, I have an 32-bit, unsigned, integer TIFF raster. The NoData value is, as expected, 4,294,967,295 (2^32-1).

The values in this raster range from only 0-7, which makes a 32-bit depth overkill. I thus decided to use the Copy Raster tool to reduce the bit depth, using Pixel Type = 4-bit. The tool help states that the output will be an "…unsigned integer. The values supported can be from 0 to 15."

However, the tool's default output NoData Value is -1. Sure enough, when using this default setting, the output is an unsigned 4-bit TIFF, where the NoData value = -1.

As far as I know, unsigned rasters can only contain positive values. Since my output TIFF is unsigned, I would thus expect its NoData value to also be a positive integer, just as in the source 32-bit unsigned integer TIFF.

How can an unsigned integer TIFF contain a negative NoData value?

I'm asking this question in order to better understand raster technology in general. I'm not asking how to "force" a postive NoData output value, which could be done by selecting a positive value in the Copy Raster tool, or by using the Raster Calculator, as commented by MoreMeowBell.

Best Answer

Your 4bit TIFF can't store values outside the range 0-15. Just like an 8bit unsigned (Byte) raster can not store values outside of 0-255.

The NoData value is only metadata, it's just for telling ArcGIS or other software to ignore a specific value. You can specify a NoData value that is outside the valid range of the datatype e.g. -1 in this case or -9999 if you like, but ArcGIS won't actually write -1 values to the output raster. Where there is NoData in the input raster, they will be output as 0.

I suggest it's a bug that ArcGIS allows specifying a NoData value outside the range of the output datatype and then silently writing a different value to the output raster (the minimum value of the output datatype range). The GDAL library that ArcGIS uses to write many raster formats also does this.

Input (NoData shown in black)

input

Output of Copy Raster 4bit with NoData = -1

output

gdalinfo test_4bit.tif
Driver: GTiff/GeoTIFF
<snip...>
Band 1 ... Type=Byte, ...
  NoData Value=-1
  Image Structure Metadata:
    NBITS=4

As you have noticed, QGIS ignores the NoData value as it's outside the valid range of the datatype:

enter image description here

Related Question