White tiles for geotiff (jpeg rgb + alpha, tiles, pyramid)

We have a lot of geotiffs generated using Agisoft and saved with JPEG compression + alpha channel, tiles (256 x256) and pyramid.

I have used a docker image (kartoza/geoserver) to run geoserver, without the jpeg turbo plugin

The problem is the geotiffs are showing with white tiles (alpha = 0) or black (alpha = 255). All default settings were used.

Interestingly, clicking on the image shows what looks like to be a range of RGB values

GeoServer does not support RBG+Alpha with JPEG compression.
Since your alpha channel is basically just a binary mask, use gdal_translate to convert it to a RGB + mask instead, that combination should be better supported.

Something like this should work :

gdal_translate -of COG -b 1 -b 2 -b 3 -mask 4 -co COMPRESS=JPEG input.tiff output.tif

The COG output format ensures you have a GeoTIFF with tiles and overviews out of the box, the first three bands are selected for color, the 4th turned into a binary mask, and the JPEG compression is preserved. Look up the docs for more parameters to tweak the output (e.g., JPEG quality and the like).

Hope this helps

Regards,

Thanks for the response, I think the original already had a mask layer, this was the output of tiffinfo:

Image Structure Metadata:
COMPRESSION=JPEG
INTERLEAVE=PIXEL
JPEGTABLESMODE=3
JPEG_QUALITY=90
Corner Coordinates: (skipped)
Band 1 Block=256x256 Type=Byte, ColorInterp=Red
Overviews: 12907x15306, 6454x7653, 3227x3827, 1614x1914, 807x957, 404x479, 202x240
Mask Flags: PER_DATASET ALPHA
Overviews of mask band: 12907x15306, 6454x7653, 3227x3827, 1614x1914, 807x957, 404x479, 202x240
Unit Type: metre
Band 2 Block=256x256 Type=Byte, ColorInterp=Green
Overviews: 12907x15306, 6454x7653, 3227x3827, 1614x1914, 807x957, 404x479, 202x240
Mask Flags: PER_DATASET ALPHA
Overviews of mask band: 12907x15306, 6454x7653, 3227x3827, 1614x1914, 807x957, 404x479, 202x240
Unit Type: metre
Band 3 Block=256x256 Type=Byte, ColorInterp=Blue
Overviews: 12907x15306, 6454x7653, 3227x3827, 1614x1914, 807x957, 404x479, 202x240
Mask Flags: PER_DATASET ALPHA
Overviews of mask band: 12907x15306, 6454x7653, 3227x3827, 1614x1914, 807x957, 404x479, 202x240
Unit Type: metre
Band 4 Block=256x256 Type=Byte, ColorInterp=Alpha
Overviews: 12907x15306, 6454x7653, 3227x3827, 1614x1914, 807x957, 404x479, 202x240
Unit Type: metre

In any case, using the command you provided make a new tiff, but with no transparency layer. I got a few errors like “ERROR 5: GDALDataset::GetRasterBand(3) - Illegal band #” at the start of conversion

I tried to make a new style to exclude the 4th layer, which seemed to work, however all the colours came out inverted. Any ideas?

<?xml version="1.0" encoding="UTF-8"?>



rgb_onlg

A raster style





1


2


3







Hum… no idea. The command I’ve shared was succesfully tested against a RGBA image I had locally.

Let’s see if anyone else has a clue

Cheers
Andrea

Try sharing the style again. Didn’t come through. You shouldn’t need a custom style though, the resulting image from the command above would only have 3 bands.