[gdal-dev] Potential issue with gdaladdo overviews setting alpha channel to nodata value instead of zero

Tim Waters chippy2005 at gmail.com
Thu Oct 5 10:46:32 PDT 2017


Hello,

I'm seeing an issue which is present in 2.2.2 (tags/2.2.2 from github) and
seen in 1.11.3 (Ubuntu 16.04) but not present in 1.10.1 (Ubuntu 14.04).

If a raster with an alpha channel has nodata set, and overviews via
gdaladdo are created, the overviews use the nodata value for the value of
the alpha channel.  However, using the nearest resampling method correctly
sets the alpha to zero. All other resampling methods except nearest seem to
give the same wrong result.

I've created a repository with all the files and readme containing the
workflow.
https://github.com/timwaters/gdal_gdaladdo_issue with screenshots of the
expected and observed files opened in Gimp to view the pixel values.

The use case is mapwarper.net where users upload ungeoreferenced images,
they get converted to tifs and have overviews added, then they can mask
them (gdal_rasterize) and then warp the masked files, with overviews added
finally. I'm updating the server to run on Ubuntu 16.04 and will have to
compile gdal.

Flow is:

#Apply overviews to ungeoreferenced raster
gdaladdo -r average treasure_island.tif 2 4 8 16

#Rasterise ungeoreferenced raster with the cropping mask
gdal_rasterize -i  -b 1 -b 2 -b 3 -burn 17 -burn 17 -burn 17  20.gml -l
features treasure_island.tif

#Georeference & warp the raster
gdal_translate -a_srs '+init=epsg:4326' -of VRT treasure_island.tif
temp.vrt  -gcp 100.38, 83.096, -122.377, 37.830 -gcp 430.1966, 370.08,
-122.363, 37.8207 -gcp 313.69, 61.68, -122.368, 37.831
gdalwarp -rn  -dstalpha -srcnodata '17 17 17' -s_srs 'EPSG:4326' temp.vrt
treasure_island_warped.tif -co TILED=YES -co COMPRESS=LZW

#Apply overviews to georeferenced raster
gdaladdo -r average treasure_island_warped.tif 2 4 8 16

Expected - transparent areas in overviews should be 17,17,17 with alpha
channel set to 0
Observed - transparent areas in overviews are 17,17,17 with alpha also set
to 17

Potential workarounds are 1) to set the nodata value to 0 instead of 17,
however a few maps uploaded are black and white scans and so this might not
be good for those maps which have pure black in them (that's why I'm using
the 17 value), and 2) to use nearest neighbour for resampling, but it does
not look good at all online.

many thanks in advance and your help is appreciated!

Regards,

Tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20171005/0637efbc/attachment.html>


More information about the gdal-dev mailing list