[gdal-dev] GDAL translate 16 bit to 8 bit

Hanlie Pretorius hanlie.pretorius at gmail.com
Wed Aug 20 23:57:32 PDT 2014


Hi,

I'm working with a 16 bit SPOT 6 image that I want to convert from 16
bit pixel depth to 8 bit pixel depth. I say 16 bit, but if I load the
file into Envi, it reports that uses only 12 bits. However gdalinfo
reports 16 bit (see below).

I've manage to do so on the multispectral image, but the result is
poor colour wise.

So I split the image into its four bands that is, I now have one image per band.

When I now try to convert to 8 bit, I get a message that says:
"Warning 742327101_R1C1_band1_8bit.TIF not created".

The command I'm using is:
gdal_translate -ot Byte -of GTiff "D:/SPOT
6/EightBit/IMG_SPOT6_MS_201304290812030_ORT_742327101_R1C1_band1.TIF"
742327101_R1C1_band1_8bit.TIF

gdalinfo for the original MS image gives the following result:
Driver: GTiff/GeoTIFF
Files: D:/SPOT 6/SANSA_SouthAfr_246_SO13012989_43_DS_SPOT6_201304290812030_FR1_FR1_SE1_SE1_E021S32_03414/PROD_SPOT6_001/VOL_SPOT6_001_A/IMG_SPOT6_MS_001_A/IMG_SPOT6_MS_201304290812030_ORT_742327101_R1C1.TIF
       D:/SPOT 6/SANSA_SouthAfr_246_SO13012989_43_DS_SPOT6_201304290812030_FR1_FR1_SE1_SE1_E021S32_03414/PROD_SPOT6_001/VOL_SPOT6_001_A/IMG_SPOT6_MS_001_A/IMG_SPOT6_MS_201304290812030_ORT_742327101_R1C1.tif.ovr
       D:/SPOT 6/SANSA_SouthAfr_246_SO13012989_43_DS_SPOT6_201304290812030_FR1_FR1_SE1_SE1_E021S32_03414/PROD_SPOT6_001/VOL_SPOT6_001_A/IMG_SPOT6_MS_001_A/IMG_SPOT6_MS_201304290812030_ORT_742327101_R1C1.TFW
       D:/SPOT 6/SANSA_SouthAfr_246_SO13012989_43_DS_SPOT6_201304290812030_FR1_FR1_SE1_SE1_E021S32_03414/PROD_SPOT6_001/VOL_SPOT6_001_A/IMG_SPOT6_MS_001_A/IMG_SPOT6_MS_201304290812030_ORT_742327101_R1C1.TIF.aux.xml
Size is 7680, 7680
Coordinate System is:
PROJCS["WGS 84 / UTM zone 34S",
    GEOGCS["WGS 84",
        DATUM["WGS_1984",
            SPHEROID["WGS 84",6378137,298.257223563,
                AUTHORITY["EPSG","7030"]],
            AUTHORITY["EPSG","6326"]],
        PRIMEM["Greenwich",0],
        UNIT["degree",0.0174532925199433],
        AUTHORITY["EPSG","4326"]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",21],
    PARAMETER["scale_factor",0.9996],
    PARAMETER["false_easting",500000],
    PARAMETER["false_northing",10000000],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AUTHORITY["EPSG","32734"]]
Origin = (426894.000000000000000,6421830.000000000000000)
Pixel Size = (6.000000000000000,-6.000000000000000)
Metadata:
  AREA_OR_POINT=Area
  TIFFTAG_DATETIME=2013:12:05 14:23:06
  TIFFTAG_IMAGEDESCRIPTION=B2, B1, B0, B3
  TIFFTAG_XRESOLUTION=6
  TIFFTAG_YRESOLUTION=6
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (  426894.000, 6421830.000) ( 20d13'23.42"E, 32d20'16.91"S)
Lower Left  (  426894.000, 6375750.000) ( 20d13'10.50"E, 32d45'13.25"S)
Upper Right (  472974.000, 6421830.000) ( 20d42'46.12"E, 32d20'24.35"S)
Lower Right (  472974.000, 6375750.000) ( 20d42'41.34"E, 32d45'20.81"S)
Center      (  449934.000, 6398790.000) ( 20d28' 0.35"E, 32d32'49.70"S)
Band 1 Block=7680x128 Type=UInt16, ColorInterp=Red
  Min=0.000 Max=2768.000
  Minimum=0.000, Maximum=2768.000, Mean=254.357, StdDev=82.827
  Overviews: 3840x3840, 1920x1920, 960x960, 480x480, 240x240
  Metadata:
    STATISTICS_COVARIANCES=6860.33555334015,5408.39177012214,3932.59000707709,8359.55872888383
    STATISTICS_MAXIMUM=2768
    STATISTICS_MEAN=254.35743888007
    STATISTICS_MINIMUM=0
    STATISTICS_SKIPFACTORX=1
    STATISTICS_SKIPFACTORY=1
    STATISTICS_STDDEV=82.827142612432
Band 2 Block=7680x128 Type=UInt16, ColorInterp=Green
  Min=0.000 Max=1928.000
  Minimum=0.000, Maximum=1928.000, Mean=272.449, StdDev=67.362
  Overviews: 3840x3840, 1920x1920, 960x960, 480x480, 240x240
  Metadata:
    STATISTICS_COVARIANCES=5408.39177012214,4537.57701249689,3512.4873688442,6910.89114933438
    STATISTICS_MAXIMUM=1928
    STATISTICS_MEAN=272.44932240804
    STATISTICS_MINIMUM=0
    STATISTICS_SKIPFACTORX=1
    STATISTICS_SKIPFACTORY=1
    STATISTICS_STDDEV=67.361539564479
Band 3 Block=7680x128 Type=UInt16, ColorInterp=Blue
  Min=0.000 Max=2264.000
  Minimum=0.000, Maximum=2264.000, Mean=291.925, StdDev=54.875
  Overviews: 3840x3840, 1920x1920, 960x960, 480x480, 240x240
  Metadata:
    STATISTICS_COVARIANCES=3932.59000707709,3512.4873688442,3011.23474438976,5111.02811591707
    STATISTICS_MAXIMUM=2264
    STATISTICS_MEAN=291.92457129584
    STATISTICS_MINIMUM=0
    STATISTICS_SKIPFACTORX=1
    STATISTICS_SKIPFACTORY=1
    STATISTICS_STDDEV=54.874718626976
Band 4 Block=7680x128 Type=UInt16, ColorInterp=Undefined
  Min=0.000 Max=2699.000
  Minimum=0.000, Maximum=2699.000, Mean=374.146, StdDev=115.219
  Overviews: 3840x3840, 1920x1920, 960x960, 480x480, 240x240
  Metadata:
    STATISTICS_COVARIANCES=8359.55872888383,6910.89114933438,5111.02811591707,13275.4755734648
    STATISTICS_MAXIMUM=2699
    STATISTICS_MEAN=374.14637317234
    STATISTICS_MINIMUM=0
    STATISTICS_SKIPFACTORX=1
    STATISTICS_SKIPFACTORY=1
    STATISTICS_STDDEV=115.21925001259

gdalinfo for band 1 of the image that I'm trying to use for the
conversion, gives the following results:
Driver: GTiff/GeoTIFF
Files: D:/SPOT 6/SANSA_SouthAfr_246_SO13012989_43_DS_SPOT6_201304290812030_FR1_FR1_SE1_SE1_E021S32_03414/PROD_SPOT6_001/VOL_SPOT6_001_A/IMG_SPOT6_MS_001_A/IMG_SPOT6_MS_201304290812030_ORT_742327101_R1C1.TIF
       D:/SPOT 6/SANSA_SouthAfr_246_SO13012989_43_DS_SPOT6_201304290812030_FR1_FR1_SE1_SE1_E021S32_03414/PROD_SPOT6_001/VOL_SPOT6_001_A/IMG_SPOT6_MS_001_A/IMG_SPOT6_MS_201304290812030_ORT_742327101_R1C1.tif.ovr
       D:/SPOT 6/SANSA_SouthAfr_246_SO13012989_43_DS_SPOT6_201304290812030_FR1_FR1_SE1_SE1_E021S32_03414/PROD_SPOT6_001/VOL_SPOT6_001_A/IMG_SPOT6_MS_001_A/IMG_SPOT6_MS_201304290812030_ORT_742327101_R1C1.TFW
       D:/SPOT 6/SANSA_SouthAfr_246_SO13012989_43_DS_SPOT6_201304290812030_FR1_FR1_SE1_SE1_E021S32_03414/PROD_SPOT6_001/VOL_SPOT6_001_A/IMG_SPOT6_MS_001_A/IMG_SPOT6_MS_201304290812030_ORT_742327101_R1C1.TIF.aux.xml
Size is 7680, 7680
Coordinate System is:
PROJCS["WGS 84 / UTM zone 34S",
    GEOGCS["WGS 84",
        DATUM["WGS_1984",
            SPHEROID["WGS 84",6378137,298.257223563,
                AUTHORITY["EPSG","7030"]],
            AUTHORITY["EPSG","6326"]],
        PRIMEM["Greenwich",0],
        UNIT["degree",0.0174532925199433],
        AUTHORITY["EPSG","4326"]],
    PROJECTION["Transverse_Mercator"],
    PARAMETER["latitude_of_origin",0],
    PARAMETER["central_meridian",21],
    PARAMETER["scale_factor",0.9996],
    PARAMETER["false_easting",500000],
    PARAMETER["false_northing",10000000],
    UNIT["metre",1,
        AUTHORITY["EPSG","9001"]],
    AUTHORITY["EPSG","32734"]]
Origin = (426894.000000000000000,6421830.000000000000000)
Pixel Size = (6.000000000000000,-6.000000000000000)
Metadata:
  AREA_OR_POINT=Area
  TIFFTAG_DATETIME=2013:12:05 14:23:06
  TIFFTAG_IMAGEDESCRIPTION=B2, B1, B0, B3
  TIFFTAG_XRESOLUTION=6
  TIFFTAG_YRESOLUTION=6
Image Structure Metadata:
  INTERLEAVE=BAND
Corner Coordinates:
Upper Left  (  426894.000, 6421830.000) ( 20d13'23.42"E, 32d20'16.91"S)
Lower Left  (  426894.000, 6375750.000) ( 20d13'10.50"E, 32d45'13.25"S)
Upper Right (  472974.000, 6421830.000) ( 20d42'46.12"E, 32d20'24.35"S)
Lower Right (  472974.000, 6375750.000) ( 20d42'41.34"E, 32d45'20.81"S)
Center      (  449934.000, 6398790.000) ( 20d28' 0.35"E, 32d32'49.70"S)
Band 1 Block=7680x128 Type=UInt16, ColorInterp=Red
  Min=0.000 Max=2768.000
  Minimum=0.000, Maximum=2768.000, Mean=254.357, StdDev=82.827
  Overviews: 3840x3840, 1920x1920, 960x960, 480x480, 240x240
  Metadata:
    STATISTICS_COVARIANCES=6860.33555334015,5408.39177012214,3932.59000707709,8359.55872888383
    STATISTICS_MAXIMUM=2768
    STATISTICS_MEAN=254.35743888007
    STATISTICS_MINIMUM=0
    STATISTICS_SKIPFACTORX=1
    STATISTICS_SKIPFACTORY=1
    STATISTICS_STDDEV=82.827142612432
Band 2 Block=7680x128 Type=UInt16, ColorInterp=Green
  Min=0.000 Max=1928.000
  Minimum=0.000, Maximum=1928.000, Mean=272.449, StdDev=67.362
  Overviews: 3840x3840, 1920x1920, 960x960, 480x480, 240x240
  Metadata:
    STATISTICS_COVARIANCES=5408.39177012214,4537.57701249689,3512.4873688442,6910.89114933438
    STATISTICS_MAXIMUM=1928
    STATISTICS_MEAN=272.44932240804
    STATISTICS_MINIMUM=0
    STATISTICS_SKIPFACTORX=1
    STATISTICS_SKIPFACTORY=1
    STATISTICS_STDDEV=67.361539564479
Band 3 Block=7680x128 Type=UInt16, ColorInterp=Blue
  Min=0.000 Max=2264.000
  Minimum=0.000, Maximum=2264.000, Mean=291.925, StdDev=54.875
  Overviews: 3840x3840, 1920x1920, 960x960, 480x480, 240x240
  Metadata:
    STATISTICS_COVARIANCES=3932.59000707709,3512.4873688442,3011.23474438976,5111.02811591707
    STATISTICS_MAXIMUM=2264
    STATISTICS_MEAN=291.92457129584
    STATISTICS_MINIMUM=0
    STATISTICS_SKIPFACTORX=1
    STATISTICS_SKIPFACTORY=1
    STATISTICS_STDDEV=54.874718626976
Band 4 Block=7680x128 Type=UInt16, ColorInterp=Undefined
  Min=0.000 Max=2699.000
  Minimum=0.000, Maximum=2699.000, Mean=374.146, StdDev=115.219
  Overviews: 3840x3840, 1920x1920, 960x960, 480x480, 240x240
  Metadata:
    STATISTICS_COVARIANCES=8359.55872888383,6910.89114933438,5111.02811591707,13275.4755734648
    STATISTICS_MAXIMUM=2699
    STATISTICS_MEAN=374.14637317234
    STATISTICS_MINIMUM=0
    STATISTICS_SKIPFACTORX=1
    STATISTICS_SKIPFACTORY=1
    STATISTICS_STDDEV=115.21925001259


I'm using QGIS 2.2.0 on Windows 8 as a front end to GDAL.

Can anyone perhaps see why the error is occurring or suggest an
alternative workflow?

Thanks
Hanlie


More information about the gdal-dev mailing list