[gdal-dev] Question on gdalwarp, srcnodata and dstalpha
Even Rouault
even.rouault at spatialys.com
Sun Nov 6 08:33:47 PST 2016
Le jeudi 03 novembre 2016 18:19:36, Daniele Romagnoli a écrit :
> Hi List,
> I was checking a gdalwarp (GDAL 2.1.2) invokation with a colleague and I
> have a question.
>
> I know that when warping a geotiff with internal NODATA_VALUES=0 0 0
> metadata, only RGB pixels = 0 0 0 are handled as nodata whilst pixels like
> "0 2 4", "50 0 0" will not right?
>
> In the past, I had issues using -scrnodata 0 instead of embedded
> NODATA_VALUES=0 0 0, getting results with sparse nodata around due to
> band_i = 0 being interpreted as a nodata pixels. This is why I usually
> suggest to define the NODATA_VALUES metadata to make sure only the exact
> triplet is handled as nodata.
>
> However, today we have processed a simple UTM RGB dataset (without
> NODATA_VALUES metadata defined) using this command:
> gdalwarp -t_srs EPSG:4326 -srcnodata 0 -dstnodata None -dstalpha
>
> And the result is properly rendered: the alpha mask is zero only where the
> input pixels are "0 0 0" which is exactly what we needed.
> Do something has been changed in the latest versions? Is the alpha band
> mask being set to zero only when all input pixels are zero?
Hi Daniele,
This is a good question, and I would have thought the same as you. But when
digging further, the nodata values must be indeed fully matched for all
components to consider a pixel as transparent. And this has been the case for
the last 11 years :-)) : https://trac.osgeo.org/gdal/changeset/8286
My confusion came from the fact that the default behaviour of the warping
engine used by gdalwarp is not that one (see UNIFIED_SRC_NODATA option in
http://www.gdal.org/structGDALWarpOptions.html#a0ed77f9917bb96c7a9aabd73d4d06e08),
but gdalwarp override it to have the UNIFIED_SRC_NODATA=YES behaviour.
I've also just added support in trunk to be able to specify
UNIFIED_SRC_NODATA=NO explicitly if wished.
See :
Let create a dataset with a single pixel R,G,B=10,20,30 with
gdal_translate byte.tif rgb.tif -b 1 -b 1 -b 1 -scale_1 0 255 10 10 \
-scale_2 0 255 20 20 -scale_3 0 255 30 30 -srcwin 0 0 1 1
By default:
gdalwarp rgb.tif out.tif -overwrite -srcnodata 10 -dstnodata None -dstalpha
lead to (R,G,B,A)=(10,20,30,255)
And (in trunk):
gdalwarp rgb.tif out.tif -overwrite -srcnodata 10 -dstnodata None -dstalpha \
-wo UNIFIED_SRC_NODATA=NO -wo INIT_DEST=127
lead to (R,G,B,A)=(127,20,30,255)
==> Nodata is applied band per band, and alpha is considered to be 255 as soon
as at least one band is valid.
Even
--
Spatialys - Geospatial professional services
http://www.spatialys.com
More information about the gdal-dev
mailing list