[gdal-dev] RE: Border slivers and JPEG2000 compression

Frank Warmerdam warmerdam at pobox.com
Tue Dec 30 15:36:14 EST 2008

Smith, Michael wrote:
> I never found a good solution to this - one thing I am doing is taking 
> the TIFFs and mosaicking them with their neighbors to fill these slivers 
> with data from the adjacent tile, so there are no slivers.  That is a 
> brute-force and inelegant solution though.
> Any suggestions on how to keep border pixels with value 0 in a TIFF to 
> stay 0 in a resulting JP2 (with Kakadu) in GDAL?


I apologize for not having responded before.

One approach to this I have seen in other contexts, is to keep a distinct
alpha layer in a separate file and used to mask the nodata areas.  Then
represent the jpeg2000 RGB image + the nodata/alpha band from another file
as a complete RGBA dataset using a VRT file.

So we have:

RGB JPEG2000 file  (eg. rgb.jp2)
Alpha-Mask File    (eg. mask.tif)
a VRT XML file     (eg. rgba.vrt)

The VRT will refer to the RGB file for the first three bands, and the
mask file for the forth alpha band.  The alpha band can be compressed
using something like Deflate compression which will work very well for
a band that is all values of 0 and 255.

This sort of approach is complicated, and their is some access overhead
but it does allow jpeg2000 lossy compression with unambigious masking
for use in MapServer or other RGBA aware GDAL applications.

The alpha mask file needs to be generated from the original files before

Best regards,
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent

More information about the gdal-dev mailing list