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

Jukka Rahkonen jukka.rahkonen at mmmtike.fi
Fri Dec 19 04:53:57 EST 2008


Smith, Michael <Michael.Smith <at> maine.gov> writes:

> 
> I tried that but it doesn't seem to write to JP2KAK.  If I do this:
> 
> nearblack mosaic_jp2.jp2
> 
> I get this error:
> 0...10..ERROR 6: WriteBlock() not supported for this dataset.
> ERROR 1: GetBlockRef failed at X block offset 1, Y block offset 19
> ERROR 6: WriteBlock() not supported for this dataset.
> ERROR 6: WriteBlock() not supported for this dataset.
> ERROR 6: WriteBlock() not supported for this dataset.
> ERROR 6: WriteBlock() not supported for this dataset.
> 
> I have also tried creating an alpha channel with this:
> gdalwarp -srcnodata 0 -dstalpha *.tif mosaic.tif
> gdal_translate -ot Byte -of JP2KAK mosaic.tif mosaic_jp2.jp2
> 
> That works, but provides a JP2 that is twice the size since it has a
> second band (these are black-and-white images, so one 8-bit band).  I
> tried converting that to a single-band image, hoping it would interpret
> the alpha channel correctly, with this:
> 
> gdal_translate -ot Byte -of JP2KAK -b 1 -a_nodata 0 mosaic_jp2.jp2
> mosaic2_jp2.jp2
> 
> But the output again has a bunch of pixels on the edge which are now not
> value 0.
> 
> I cannot gdal_rasterize -burn the JP2 because gdal_rasterize does not
> write JP2KAK (why is that?  gdal_translate will but not gdal_rasterize)?
> 
> It seems like all the functions I need to work only do so on TIFFs, but
> it's the JP2s I need it to work on.
> 
> Any other suggestions?  Some trick involving alpha channels I don't
> know?  A way to get gdal_rasterize to write JP2KAK?

Hi,

I fear that wavelet compression like in JPEG2000, MrSID and ECW can't keep
black areas totally black.  It theory you could save in file size by 
adding a 1-bit alpha channel to JPEG2000 image, but I do not know how 
to create it and if any program would support using it. If the aim is 
to use JPEG2000 without the disturbing slivers then it might be best 
to get rid of those. Steps to do this are:

1. Make a virtual mosaic from the original tiff files.  There is an
utility for doing that, and perhaps it is this one:
http://www.vso.cape.com/~nhv/files/gdal/gdal_vrtmerge.py

(By the way, I wonder why standard gdal_merge.py can't have .vrt 
output as an option.)
Creating a virtual mosaic takes only seconds because it does not 
touch the images but it creates only a .vrt file telling how to read 
the originals.

2. Create new rectangular mosaiced images without any black slivers 
by using the .vrt file as an input for gdalwarp program.  That can be 
done with gdalwarp by giving the target extents with -te switch. Gdalwarp
should be able to write out JPEG2000 directly.

I do know that the system works but my instructions may be inaccurate 
because I could not find a working installation from my computer any 
more.

-Jukka Rahkonen-





More information about the gdal-dev mailing list