0

How to blend multiple overlapping semi-transparent GeoTIFFs to single semi-transparent GeoTIFF on Linux (GDAL...) ?

  • 1
    I would evaluate first VRT with derived bands gdal.org/gdal_vrttut.html#gdal_vrttut_derived_c – user30184 Jan 30 '19 at 15:19
  • Could you expand a bit on the software you're using, what you tried so far and where you're stuck? – Erik Jan 30 '19 at 16:25
  • I use linux and tried nothing yet because I found nothing how to do it. – Martin Ždila Jan 30 '19 at 19:26
0

I've ended up with the following script:

(input files are layer1.tiff and layer2.tiff; output is blended.tiff)

FORMULA='(1.0*A*B/255.0 + 1.0*C*D/255.0*(1.0 - 1.0*B/255.0)) / (1.0*B/255.0 + 1.0*D/255.0*(1.0 - 1.0*B/255.0))'

# compute each color band
gdal_calc.py -A layer1.tiff -B layer1.tiff --A_band=1 --B_band=4 -C layer2.tiff -D layer2.tiff --C_band=1 --D_band=4 --outfile=R.tiff --calc="$FORMULA" --type=Byte
gdal_calc.py -A layer1.tiff -B layer1.tiff --A_band=2 --B_band=4 -C layer2.tiff -D layer2.tiff --C_band=2 --D_band=4 --outfile=G.tiff --calc="$FORMULA" --type=Byte
gdal_calc.py -A layer1.tiff -B layer1.tiff --A_band=3 --B_band=4 -C layer2.tiff -D layer2.tiff --C_band=3 --D_band=4 --outfile=B.tiff --calc="$FORMULA" --type=Byte

# compute alpha
gdal_calc.py -A layer1.tiff --A_band=4 -B layer2.tiff --B_band=4 --outfile=A.tiff --calc='255.0*(1.0*B/255.0 + 1.0*D/255.0 - 1.0*B/255.0*D/255.0)' --type=Byte

# join bands
gdal_merge.py -separate -o blended.tiff R.tiff G.tiff B.tiff A.tiff

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.