0

I'm working on a project that involves generating tiles from several geotiffs, and I've found that several of them are producing these odd, greyish maps that look almost, but not quite like what they're supposed to represent.I found this conversation, which describes an issue similar to mine, but my geotiffs are already in a 3-band rgb color format (not sure if I'm using those terms correctly, still fairly new).

What's worked best so far is converting the images to pct and then back to rgb, so running rgb2pct.py then pct2rgb.py from gdal. It does produce tiles with accurate colors, but it doesn't preserve transparency around the edges of the maps, so my maps all have white boxes around them.

My main question is whether there's a more sensible way to do this, preferably one that preserves transparency. Here is a sample gdalinfo from one of the files that comes out grey:

Driver: GTiff/GeoTIFF
Files: 44717623_geotiff.tif
       44717623_geotiff.tif.ovr
       44717623_geotiff.tfw
       44717623_geotiff.tif.aux.xml
Size is 8332, 4706
Coordinate System is:
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"]]
Origin = (-33.848244385298720,43.625496400833775)
Pixel Size = (0.004133000000000,-0.004133000000000)
Metadata:
  AREA_OR_POINT=Area
  DataType=Generic
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  ( -33.8482444,  43.6254964) ( 33d50'53.68"W, 43d37'31.79"N)
Lower Left  ( -33.8482444,  24.1755984) ( 33d50'53.68"W, 24d10'32.15"N)
Upper Right (   0.5879116,  43.6254964) (  0d35'16.48"E, 43d37'31.79"N)
Lower Right (   0.5879116,  24.1755984) (  0d35'16.48"E, 24d10'32.15"N)
Center      ( -16.6301664,  33.9005474) ( 16d37'48.60"W, 33d54' 1.97"N)
Band 1 Block=128x128 Type=UInt16, ColorInterp=Gray
  Min=0.000 Max=255.000 
  Minimum=0.000, Maximum=255.000, Mean=203.216, StdDev=39.785
  NoData Value=256
  Overviews: 4166x2353, 2083x1177, 1042x589, 521x295, 261x148
  Metadata:
    STATISTICS_MAXIMUM=255
    STATISTICS_MEAN=203.21584345707
    STATISTICS_MINIMUM=0
    STATISTICS_STDDEV=39.785493648664
Band 2 Block=128x128 Type=UInt16, ColorInterp=Undefined
  Min=0.000 Max=255.000 
  Minimum=0.000, Maximum=255.000, Mean=188.044, StdDev=40.836
  NoData Value=256
  Overviews: 4166x2353, 2083x1177, 1042x589, 521x295, 261x148
  Metadata:
    STATISTICS_MAXIMUM=255
    STATISTICS_MEAN=188.04388506804
    STATISTICS_MINIMUM=0
    STATISTICS_STDDEV=40.836125556927
Band 3 Block=128x128 Type=UInt16, ColorInterp=Undefined
  Min=0.000 Max=251.000 
  Minimum=0.000, Maximum=251.000, Mean=163.610, StdDev=40.507
  NoData Value=256
  Overviews: 4166x2353, 2083x1177, 1042x589, 521x295, 261x148
  Metadata:
    STATISTICS_MAXIMUM=251
    STATISTICS_MEAN=163.61017219835
    STATISTICS_MINIMUM=0
    STATISTICS_STDDEV=40.507221757425

And here's one that came out fine:

Driver: GTiff/GeoTIFF
Files: 43607115_geotiff.tif
       43607115_geotiff.tif.ovr
       43607115_geotiff.tfw
       43607115_geotiff.tif.aux.xml
Size is 10104, 4480
Coordinate System is:
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"]]
Origin = (2.140456086335875,53.243297548501296)
Pixel Size = (0.000364000000000,-0.000364000000000)
Metadata:
  AREA_OR_POINT=Area
Image Structure Metadata:
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (   2.1404561,  53.2432975) (  2d 8'25.64"E, 53d14'35.87"N)
Lower Left  (   2.1404561,  51.6125775) (  2d 8'25.64"E, 51d36'45.28"N)
Upper Right (   5.8183121,  53.2432975) (  5d49' 5.92"E, 53d14'35.87"N)
Lower Right (   5.8183121,  51.6125775) (  5d49' 5.92"E, 51d36'45.28"N)
Center      (   3.9793841,  52.4279375) (  3d58'45.78"E, 52d25'40.58"N)
Band 1 Block=128x128 Type=Byte, ColorInterp=Red
  Min=0.000 Max=250.000 
  Minimum=0.000, Maximum=250.000, Mean=140.833, StdDev=87.477
  NoData Value=256
  Overviews: 5052x2240, 2526x1120, 1263x560, 632x280, 316x140
  Metadata:
    STATISTICS_MAXIMUM=250
    STATISTICS_MEAN=140.8329810153
    STATISTICS_MINIMUM=0
    STATISTICS_STDDEV=87.47681372057
Band 2 Block=128x128 Type=Byte, ColorInterp=Green
  Min=0.000 Max=229.000 
  Minimum=0.000, Maximum=229.000, Mean=128.612, StdDev=80.491
  NoData Value=256
  Overviews: 5052x2240, 2526x1120, 1263x560, 632x280, 316x140
  Metadata:
    STATISTICS_MAXIMUM=229
    STATISTICS_MEAN=128.61218108458
    STATISTICS_MINIMUM=0
    STATISTICS_STDDEV=80.491408161142
Band 3 Block=128x128 Type=Byte, ColorInterp=Blue
  Min=0.000 Max=253.000 
  Minimum=0.000, Maximum=253.000, Mean=106.614, StdDev=67.324
  NoData Value=256
  Overviews: 5052x2240, 2526x1120, 1263x560, 632x280, 316x140
  Metadata:
    STATISTICS_MAXIMUM=253
    STATISTICS_MEAN=106.61403479704
    STATISTICS_MINIMUM=0
    STATISTICS_STDDEV=67.323608969824

I think that there's something the matter with the color interpolation, but I don't know how to address it.

1

To get the colors interpreted properly, I did a gdal_translate -ot Byte on the files, and that allowed the colors to be interpreted properly. Apparently gdal2tiles interprets files with 3 byte type bands as rgb, which is what I wanted. However, when I did this, I still had some white boxes around my images. This turned out to just be an export setting from ArcMap that wasn't changed, so NoData was being represented as white instead of as nothing.

The eventual fix was to just run gdal2tiles on the original jp2 files with associated world files, instead of the oddly exported geotiffs, which I didn't originally know was possible.

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.