[GIS] Geotiff smallest bit depth value

bit depthfile sizegdalgeotiff-tiffpython

I have a geotiff (RGB) 8-bit per channel file that was classsified to four classes. Theoreitcally I could save the file as a 3-bit and make the file significantly smaller. For my application files size is very important. Yet from what I can tell from the GDAL documentation http://www.gdal.org/frmt_gtiff.html I think am out of luck. Since each pixel is a stand-alone, aggregating the pixels and converting them into a polygon does not seem it would do the trick. For my processes I have been using GDAL API with Python 3.5.
Does anyone have any thoughts on how to take advntage of the classified data to convert to s smaller file size?

Best Answer

You can make your image significantly smaller by converting it into a single-band paletted tiff with rgb2pct.py. Moreover, you can continue and reduce the bit depth of the single band tiff with gdal_translate by using the GeoTIFF creation option "nbits" as documented in http://www.gdal.org/frmt_gtiff.html. Using compression will reduce the file size further.

I made a simple test with the following commands

rgb2pct test.tif test_palette.tif
gdal_translate -of GTiff -co nbits=3 test_palette.tif test_palette_3bit.tif
gdal_translate -of GTiff -co compress=DEFLATE test_palette_3bit.tif test_palette_3bit_deflate.tif

Here are the file sizes of the original file and the three processed files

test.tif                        10 264 936  
test_palette.tif                 3 422 122  
test_palette_3bit.tif            1 282 834  
test_palette_3bit_deflate.tif      113 183