<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Javier,</p>
<br>
<blockquote type="cite"
cite="mid:CADRrdKu0z8O8uYNR7AGT6Pwpvn4=8VWs3VF6ZsKB_eDUF-AufA@mail.gmail.com">
<div dir="ltr">
<div>I have not looked at the code, but seems that the mask is
requested only for the first band.</div>
</div>
</blockquote>
<p>You're right. GDALRegenerateOverviewsMultiBand() in
<a class="moz-txt-link-freetext" href="https://github.com/OSGeo/gdal/blob/master/gdal/gcore/overview.cpp#L5057">https://github.com/OSGeo/gdal/blob/master/gdal/gcore/overview.cpp#L5057</a>
always takes the mask from the first band. Which is OK for an
alpha band or a per-dataset materialized mask, but not for nodata.
Please file a ticket about that.</p>
<p>Even<br>
</p>
<p><br>
</p>
<blockquote type="cite"
cite="mid:CADRrdKu0z8O8uYNR7AGT6Pwpvn4=8VWs3VF6ZsKB_eDUF-AufA@mail.gmail.com">
<div dir="ltr">
<div> Then the pixels in the other bands that are nodata, but
are valid in the first band are computed as valid... using
-10000 in this case. Looks like requesting the mask per band
would fix it, right?</div>
<div><br>
</div>
<div>If this is the case, the alpha band is not the problem
(confirmed removing it from the tmp.vrt file).<br>
</div>
<div><br>
</div>
<div>Cheers<br>
</div>
<div>
<div>
<div dir="ltr" class="gmail_signature"
data-smartmail="gmail_signature">.___ ._ ..._ .. . ._.
.___ .. __ . _. . __.. ... .... ._ .__<br>
Entre dos pensamientos racionales <br>
hay infinitos pensamientos irracionales.<br>
<br>
</div>
</div>
<br>
</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Mon, 31 May 2021 at 17:28,
Even Rouault <<a href="mailto:even.rouault@spatialys.com"
moz-do-not-send="true">even.rouault@spatialys.com</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote">
<div>
<p>Javier,</p>
<p>mixing Alpha and NoData is generally not a good idea.
Behavior will be different according to which part of the
code is triggered. As far as I can see, the warping code
should be able to handle both, but overview building will
use the return of GDALRasterBand::GetMaskBand(), and when
you have both nodata and alpha, this should be from the
nodata value.</p>
<p>Confirmed by the following little experiment, so I'm not
sure why you get what you get:<br>
</p>
<p>$ cat test.asc<br>
ncols 2<br>
nrows 2<br>
xllcorner 440720.000000000000<br>
yllcorner 3750120.000000000000<br>
cellsize 60.000000000000<br>
NODATA_value -10000<br>
0.5 1.0<br>
2.5 -10000</p>
<p>$ cat test_alpha.asc <br>
ncols 2<br>
nrows 2<br>
xllcorner 440720.000000000000<br>
yllcorner 3750120.000000000000<br>
cellsize 60.000000000000<br>
NODATA_value -10000<br>
255 255<br>
255 255</p>
<p>$ cat tmp.vrt <br>
<VRTDataset rasterXSize="2" rasterYSize="2"><br>
<GeoTransform> 4.4072000000000000e+05,
6.0000000000000000e+01, 0.0000000000000000e+00,
3.7513200000000000e+06, 0.0000000000000000e+00,
-6.0000000000000000e+01</GeoTransform><br>
<VRTRasterBand dataType="Float32" band="1"><br>
<NoDataValue>-10000</NoDataValue><br>
<ComplexSource><br>
<SourceFilename
relativeToVRT="1">test.asc</SourceFilename><br>
<SourceBand>1</SourceBand><br>
<NODATA>-10000</NODATA><br>
</ComplexSource><br>
</VRTRasterBand><br>
<VRTRasterBand dataType="Float32" band="2"><br>
<NoDataValue>-10000</NoDataValue><br>
<ColorInterp>Alpha</ColorInterp><br>
<ComplexSource><br>
<SourceFilename
relativeToVRT="1">test_alpha.asc</SourceFilename><br>
<SourceBand>1</SourceBand><br>
<NODATA>-10000</NODATA><br>
</ComplexSource><br>
</VRTRasterBand><br>
</VRTDataset><br>
<br>
</p>
<div>$ gdal_translate tmp.vrt test.tif<br>
</div>
<div><br>
</div>
<div>$ gdaladdo -r average test.tif 2</div>
<div><br>
</div>
<div>$ gdal_translate test.tif /vsistdout/ -of aaigrid -b 1
-outsize 1 1<br>
ncols 1<br>
nrows 1<br>
xllcorner 440720.000000000000<br>
yllcorner 3751200.000000000000<br>
cellsize 120.000000000000<br>
NODATA_value -10000<br>
1.3333333730697631836<br>
</div>
<div><br>
</div>
<div>Even<br>
</div>
<div><br>
</div>
<div>Le 31/05/2021 à 16:55, Javier Jimenez Shaw a écrit :<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div>Hi</div>
<div><br>
</div>
<div>I have a GeoTIFF with this characteristics:</div>
<div>- 6 bands</div>
<div>- last band is "Alpha" (with values 0 or 255,
nothing else)<br>
</div>
<div>- Float32</div>
<div>- NoData value = -10000</div>
<div><br>
</div>
<div>The 5 first bands may have "nodata" pixels, not
necessarily on all bands simultaneously. (nodata
pixels are usually broken or saturated pixels from the
sensor, and each band comes from a different sensor).
The valid pixels have values between 0 and 1</div>
<div><br>
</div>
<div>When I try to generate embedded overviews (with
average interpolation) with C++ or CreateCopy as COG
(with default values), looks like it is using the
-10000 values as valid values, and producing results
in the overviews like -9990.6... that obviously are
not anymore considered "nodata".</div>
<div><br>
</div>
<div>The first noticeable effect opening the file in
QGIS, is that the min and max value for each band are
not anymore 0 and 1, but nonsense negative numbers.<br>
</div>
<div><br>
</div>
<div>Can both Alpha and NoData live together properly?</div>
<div><br>
</div>
<div>Thanks.</div>
<div><br>
</div>
<div>PS I have the impression that with external ovr
file it does not happen. I am testing more.<br>
</div>
<div>
<div>
<div>
<div dir="ltr">.___ ._ ..._ .. . ._. .___ .. __ .
_. . __.. ... .... ._ .__<br>
Entre dos pensamientos racionales <br>
hay infinitos pensamientos irracionales.<br>
<br>
</div>
</div>
</div>
</div>
</div>
<br>
<fieldset></fieldset>
<pre>_______________________________________________
gdal-dev mailing list
<a href="mailto:gdal-dev@lists.osgeo.org" target="_blank" moz-do-not-send="true">gdal-dev@lists.osgeo.org</a>
<a href="https://lists.osgeo.org/mailman/listinfo/gdal-dev" target="_blank" moz-do-not-send="true">https://lists.osgeo.org/mailman/listinfo/gdal-dev</a>
</pre>
</blockquote>
<pre cols="72">--
<a href="http://www.spatialys.com" target="_blank" moz-do-not-send="true">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre>
</div>
</blockquote>
</div>
</blockquote>
<pre class="moz-signature" cols="72">--
<a class="moz-txt-link-freetext" href="http://www.spatialys.com">http://www.spatialys.com</a>
My software is free, but my time generally not.</pre>
</body>
</html>