[gdal-dev] Create cloud optimized geotiff without re-encoding?

jratike80 jukka.rahkonen at maanmittauslaitos.fi
Thu Feb 18 03:34:20 PST 2021


Hi,

I made a couple of simple tests by following
https://trac.osgeo.org/gdal/wiki/CloudOptimizedGeoTIFF, here are the
results:

Create a jpeg compressed GeoTIFF and couple of overviews

gdal_translate -of GTiff -co tiled=yes -co compress=jpeg p4433h.tif
p2-jpeg.tif
gdaladdo --config COMPRESS_OVERVIEW JPEG p2-jpeg.tif 2 4

Test how the main image and overviews behave

gdal_translate -co tiled=yes -co COPY_SRC_OVERVIEWS=YES p2-jpeg.tif
cog21.tif
gdal_translate -co tiled=yes -co compress=jpeg -co COPY_SRC_OVERVIEWS=YES
p2-jpeg.tif cog22.tif  

Check file sizes:

575 913 074 cog21.tif
131 203 903 cog22.tif

Both images have 2 overviews and obviously the full resolution data are not
copied. I believe that it means that the jpeg compressed tiles are
uncompressed and processed again that leads into quality loss just as you
feared.

What I do not understand is what gdalcompare reports.

gdalcompare p2-jpeg.tif cog21.tif
Files differ at the binary level.
Differences Found: 1

This is understandable, the main tiles are jpeg compresses vs. uncompressed
so they are not the same. However, pixels are the same because jpeg is
converted into uncompressed with no loss.  But then, this is the beginning
of the report about original and jpeg-compressed with overviews copied.

gdalcompare p2-jpeg.tif cog28.tif
Files differ at the binary level.
Band 1 checksum difference:
  Golden: 30664
  New:    57443
  Pixels Differing: 62249009
  Maximum Pixel Difference: 13.0
Band 1 overview 0 checksum difference:
  Golden: 19959
  New:    54816
  Pixels Differing: 28090066
  Maximum Pixel Difference: 39.0
Band 1 overview 1 checksum difference:
  Golden: 5318
  New:    34525
  Pixels Differing: 8059334
  Maximum Pixel Difference: 75.0
... more bands ...


So not only the full resolution images differ but also the overviews even
they should be just copied.  I got similar results also when I used "cog" as
outputformat, and with GDAL versions 3.14 and 3.3.0. The cog driver creates
two overviews just as documented (the AUTO overview option) but gdalcompare
reports pretty large differences in pixel values.

Maybe you could just try to use your existing jpeg-in-geotiff images in
cloud. They may behave rather well even the reading application must read a
little bit more bytes from that GeoTIFF structure.

-Jukka Rahkonen-




mhw-at-yg wrote
> Hi Folks,
> 
> I have a lot of jpeg-in-geotiff imagery that I would like to convert to
> Cloud Optimized Geotiff. Is there any way to do that without re-encoding
> the
> pixel values?
> 
> I'm trying to avoid paying the price of:
> 
>     * lossy + lossy compression that results from feeding a jpeg source to
> a
> jpeg output file, and
>     * lossy + lossless that comes from feeding a jpeg source to lossless
> output file, which means x4+ storage requirements
> 
> -Matt
> 
> (x-posted to GIS Stack Exchange,
> https://gis.stackexchange.com/questions/387632)
> 
> 
> 
> -----
> -Matt
> --
> Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
> _______________________________________________
> gdal-dev mailing list

> gdal-dev at .osgeo

> https://lists.osgeo.org/mailman/listinfo/gdal-dev





--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html


More information about the gdal-dev mailing list