I want to convert an 8 bit pixel depth raster into 1 bit to reduce the file size. The raster has already been reclassified to store only 0s and 1s but the metadata still shows me 8 bit pixel depth and the file size is unnecessarily big.

I know of gdal_translate -ot parameter but the minimal depth supported is 8 bit.

I would prefer to solve this with Python but other options would also be ok.

1 Answer 1


Read the driver specific manual pages. For GeoTIFF format https://gdal.org/drivers/raster/gtiff.html

See Creation Options

NBITS=n: Create a file with less than 8 bits per sample by passing a value from 1 to 7. The apparent pixel type should be Byte. Values of n=9…15 (UInt16 type) and n=17…31 (UInt32 type) are also accepted. From GDAL 2.2, n=16 is accepted for Float32 type to generate half-precision floating point values.

Use -ot byte -co NBITS=1 in your gdal_translate command. Find out how to do the same with Python if you prefer that.

Gdalinfo shows the data type as byte but it is also telling the number of bits as 1.

gdal_translate -co nbits=1 byte.tif binary.tif Input file size is 87, 39 0...10...20...30...40...50...60...70...80...90...100 - done.

gdalinfo binary.tif
Driver: GTiff/GeoTIFF
Files: binary.tif
Size is 87, 39
Band 1 Block=87x39 Type=Byte
  Image Structure Metadata:

The data types supported by TIFF are

  1. BYTE 8-bit unsigned integer
  2. ASCII 8-bit, NULL-terminated string
  3. SHORT 16-bit unsigned integer
  4. LONG 32-bit unsigned integer
  5. RATIONAL Two 32-bit unsigned integers

Source: http://paulbourke.net/dataformats/tiff/tiff_summary.pdf

1-bit GeoTIFF contains bytes but by the metadata it is known that byte has only one meaningful bit. Such data can be compressed effectively with compression methods which were originally developed for faxes. Have a try with -co compress=CCITTFAX3 or -co compress=CCITTFAX4.

  • That did not work. The file size is still the same and the data type for pixel is still 8 bit unsigned integer. Any ideas? I used this in the gdal Translate in QGIS with the additional command -ot byte -co NBITS=1. Oct 1, 2020 at 14:16
  • If TIFF shows that NBITS=1 then it did work.
    – user30184
    Oct 1, 2020 at 14:35
  • The compress option solved the issue. Thanks. Oct 2, 2020 at 5:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.