[gdal-dev] Convert alpha to nodata?

Robert Coup robert.coup at koordinates.com
Fri Jan 19 08:40:28 PST 2024


Maybe it's just Friday, but I could use a pointer here :-)

My input raster is a RGBA byte image, where the alpha channel value is 0 or
255 (ie: effectively a mask). The output is ideally a VRT file, RGB with
Int16 data type, using nodata=-1.

So I want to convert the alpha channel to a nodata value.

The alpha/nodata/mask/band options to translate/warp haven't got me very
far, neither has hand-crafting various UseMaskBand/MaskBand elements in a
VRT.

I can do it to concrete tif files with something like this, repeating for
R,G,B and merge the output bands together, but it's a lot of processing.

  gdal_calc.py -A src.tif -B src.tif \
    --outfile out_b1.tif --co TILED=YES --type=Int16 --NoDataValue=-1 \
    --A_band=1 --B_band=4 --calc="where(B >= 128, A, -1)"

I feel like I'm probably missing a simpler path? (Which I will definitely
add to an Examples section somewhere)

Thanks,

Rob :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20240119/94c1614b/attachment.htm>


More information about the gdal-dev mailing list