I realised that perhaps I should have been expecting those
artifacts if the transparent background was essentially black with
an alpha of 0. I tried again with the background set to
255,255,255,0 but this time got even stranger (and definitely
Support Staff3 Posted by Dane on 27 Sep, 2012 04:58 PM
Can you post your raster input data so I can replicate? If it is
big please clip out just a small chunk (as small as possible). But,
before posting please make sure you can still replicate the
Support Staff9 Posted by Dane on 28 Sep, 2012 06:13 PM
Okay, thanks for the details. The problem is basically that
somewhere along that path the image is becoming "premultiplied"
which means that the alpha value is stored within each rgb channel
(e.g. by multiplying the rgb by the alpha value). Premultiplied
alpha is necessary for image blending, so Mapnik also premultiplies
the image after reading it from GDAL (it's this double
multiplication which is creating the gray fringing). Currently GDAL
provides no way to know if alpha is already premultiplied, and its
been this way for many years: http://trac.osgeo.org/gdal/ticket/2279.
So, the obvious solution is to not premultiply the image.
However, based on your steps its not obvious to me how the image is
actually getting premultiplied.
I can't figure out how it is premultiplying either. Could this
be something to do with the gdal_translate command? I see that the
bands in my tif have the flag PER_DATASET ALPHA set,
is that related? In case it helps troubleshoot, here is a crop of
the original tif from MODIS.
I have at least tracked down when the premultiplication is
happening: the raw tiff (with values 0 for land, 1 for water) is
fine. A VRT of the tiff, with -vrtnodata 0 works as
expected. Changing <ColorInterp> to
palette is what causes the problem. Even if I only use
RGB values (rather than RGBa):