0

Dark tiles are generated when I run gdal2tiles.py on a .IMG file(a scanned and georeferenced topographical map).
This question advised to apply a color relief map using gdaldem before generating tiles.
Does gdaldem work if the .IMG has no elevation data ? I tried it using the color ramp below and the output file was all green.

0 110 220 110
900 240 250 160
1300 230 220 170
1900 220 220 220
2500 250 250 250

This is because the height for all raster cells are the same, 0. Which color ramp should i use with gdaldem to prevent gdal2tiles.py from generating dark pngs ?
gdalinfo output is as below

Driver: HFA/Erdas Imagine Images (.img)
Files: ALOI.IMG
       ALOI.IMG.aux.xml
Size is 3830, 2552
Coordinate System is:
GEOGCS["GCS_WGS_1984",
    DATUM["WGS_1984",
        SPHEROID["WGS_1984",6378137.0,298.257223563]],
    PRIMEM["Greenwich",0.0],
    UNIT["Degree",0.017453292519943295]]
Origin = (32.999437318839924,3.000470692247897)
Pixel Size = (0.000392066994127,-0.000392066994127)
Metadata:
  DataType=Generic
Corner Coordinates:
Upper Left  (  32.9994373,   3.0004707) ( 32d59'57.97"E,  3d 0'1.69"N)
Lower Left  (  32.9994373,   1.9999157) ( 32d59'57.97"E,  1d59'59.70"N)
Upper Right (  34.5010539,   3.0004707) ( 34d30'3.79"E,  3d 0'1.69"N)
Lower Right (  34.5010539,   1.9999157) ( 34d30'3.79"E,  1d59'59.70"N)
Center      (  33.7502456,   2.5001932) ( 33d45'0.88"E,  2d30'0.70"N)
Band 1 Block=64x64 Type=UInt16, ColorInterp=Undefined
  Description = Layer_1
  Min=0.000 Max=255.000 
  Minimum=0.000, Maximum=255.000, Mean=225.572, StdDev=31.338
  NoData Value=256
  Overviews: 1915x1276, 958x638, 479x319, 240x160
  Metadata:
    STATISTICS_COVARIANCES=982.046346716112,845.521289084631,710.510646703791
    STATISTICS_MINIMUM=0
    STATISTICS_MAXIMUM=255
    STATISTICS_MEAN=225.57242379015
    STATISTICS_MEDIAN=0
    STATISTICS_MODE=0
    STATISTICS_STDDEV=31.337618714831
    STATISTICS_SKIPFACTORX=1
    STATISTICS_SKIPFACTORY=1
    STATISTICS_EXCLUDEDVALUES=
    LAYER_TYPE=athematic
  Image Structure Metadata:
    COMPRESSION=RLE
Band 2 Block=64x64 Type=UInt16, ColorInterp=Undefined
  Description = Layer_2
  Min=4.000 Max=255.000 
  Minimum=4.000, Maximum=255.000, Mean=226.079, StdDev=29.739
  NoData Value=256
  Overviews: 1915x1276, 958x638, 479x319, 240x160
  Metadata:
    STATISTICS_COVARIANCES=845.521289084631,884.412989496947,765.062067015664
    STATISTICS_MINIMUM=4
    STATISTICS_MAXIMUM=255
    STATISTICS_MEAN=226.07921779459
    STATISTICS_MEDIAN=0
    STATISTICS_MODE=0
    STATISTICS_STDDEV=29.739081853631
    STATISTICS_SKIPFACTORX=1
    STATISTICS_SKIPFACTORY=1
    STATISTICS_EXCLUDEDVALUES=
    LAYER_TYPE=athematic
  Image Structure Metadata:
    COMPRESSION=RLE
Band 3 Block=64x64 Type=UInt16, ColorInterp=Undefined
  Description = Layer_3
  Min=0.000 Max=255.000 
  Minimum=0.000, Maximum=255.000, Mean=172.929, StdDev=27.135
  NoData Value=256
  Overviews: 1915x1276, 958x638, 479x319, 240x160
  Metadata:
    STATISTICS_COVARIANCES=710.510646703791,765.062067015664,736.335138826829
    STATISTICS_MINIMUM=0
    STATISTICS_MAXIMUM=255
    STATISTICS_MEAN=172.92884721066
    STATISTICS_MEDIAN=0
    STATISTICS_MODE=0
    STATISTICS_STDDEV=27.135495920046
    STATISTICS_SKIPFACTORX=1
    STATISTICS_SKIPFACTORY=1
    STATISTICS_EXCLUDEDVALUES=
    LAYER_TYPE=athematic
  Image Structure Metadata:
    COMPRESSION=RLE

Is there another hack ?

Thanks,
Allan.

0

Try using byte data instead of uint16.

gdal_translate -ot byte -of vrt filename.img filename.vrt

Then run gdal2tiles.py on the vrt instead of the img.

  • Hey Luke, the png tiles generated by gdal2tiles.py on the vrt are now OK (even brighter than the original .img). Thanks alot, could you please explain why {gdal_translate -ot byte -of vrt} resulted in better tiles? Thanks again. – Allan Oware Jul 14 '14 at 11:59
  • @AllanOware Your original img was UInt16 which has possible min-max (range) values of 0-65,535. The gdal2tiles script may have performed a rescale of the actual values to convert to Byte before exporting the tiles. If it rescaled with no contrast stretch from 0-65535 to 0-255 all your values would have ended up as 0 or 1 and would be dark when output. As to why Byte input looks brighter when output, I assume when viewing the original UInt16 img, that whatever software you use applied a rescale with a contrast stretch and gdal2tiles just used the actual 0-255 RGB values (or vice versa). – user2856 Jul 16 '14 at 4:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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