[gdal-dev] Compression artifacts

Even Rouault even.rouault at mines-paris.org
Thu Dec 27 05:27:19 PST 2012


Le jeudi 27 décembre 2012 13:38:50, Jan Hartmann a écrit :
> Can anyone tell me wath is happening here? I have a large three-band
> raster (3.8G) looking like this:
> 
> http://mapserver.sara.nl/map2a.png
> 
> I compress it (from information from this list a few days ago) with:
> 
> gdal_translate -co COMPRESS=JPEG -co PHOTOMETRIC=YCBCR big.tif small.tif
> gdaladdo --config COMPRESS_OVERVIEW JPEG --config PHOTOMETRIC_OVERVIEW
> YCBCR -ro -r gauss small.tif 2 4 8 16 32 64
> 
> and get a file of 37M, which is nice. However, the map has all kinds of
> rubbish at the borders. It looks like this:
> 
> http://mapserver.sara.nl/map2b.png
> 
> The equivalent pictures of a small part of the map look like this:
> 
> http://mapserver.sara.nl/map1a.png
> http://mapserver.sara.nl/map1b.png
> 
> Can anyone help me?

The artifacts are due to the lossy characteristics of JPEG compression that 
are particularly visible on borders between nodata pixel and valid pixels. An 
option would be to use nearblack to create a .msk mask file :

nearblack -setmask -o big_with_mask.tif big.tif -of gtiff

(I'm not sure if your original image has black or white nodata areas. If it is 
white, then add -white to the previous command line)

And then do the gdal_translate with big_with_mask.tif as input (you should 
perhaps consider adding "-co TILED=YES" too), and then gdaladdo. I've just 
pushed a fix since building overviews with "--config COMPRESS_OVERVIEW JPEG --
config PHOTOMETRIC_OVERVIEW
YCBCR" when there's a .msk didn't work.

MapServer should be able to use the mask file as a transparency mask.

> 
> Jan


More information about the gdal-dev mailing list