Ticket #3847 (closed enhancement: fixed)
JPEG2000: Adding support for display resolution metadata
|Reported by:||Coatman||Owned by:||warmerdam|
|Severity:||normal||Keywords:||JP2KAK JPEG2000 resolution|
The TIFF standard provides 3 tags to define how an image should be display or printed 282=XResolution, 283=YResolution, 296=ResolutionUnit? With tag 282=200, tag 283=200, and tag 296=3, a TIFF image will be printed with 200 pixels per centimeter in X, and 200 pixels per centimeter in Y.
JPEG2000 provides a similar capability, but uses the concept of JP2 boxes, instead of TIFF tags. I find the clearest explanation of the JPEG2000 Display Resolution Box is in the book JPEG2000 Image Compression Fundamentals, Standards, and Practice by David Taubman, Chapter 14, page 589, under resd = Display Resolution Box
The differences between display resolution TIFF tags and display resolution JPEG2000 boxes are
1. While TIFF allows the tag 296=ResolutionUnit? to be of one 3 values: 1 = none, 2 = inch, 3 = centimeter, in JPEG2000 what would be the "JP2ResolutionUnit" is always meters (not centimeters), and hence "JP2ResolutionUnit" is not needed, and does not exist.
2. JPEG2000 specifies the X and Y display resolution values via the equation (resolution numerator / resolution denominator) x resolution exponent. For example, with resolution numerator = 2, resolution denominator = 1, and resolution exponent = 4, the equation is (2 / 1) * (10*10*10*10) = 2 * 10000 = 20000 pixels/meter = 200 pixels/centimeter.
In Kakadu version 6.4.1, I see in
1. apps/compressed_io/jpx.h, on line 5801, a reference to resd = Display Resolution Box
2. apps/image/image_in.cpp (that reads in a TIFF and writes out a JP2), beginning at line 2163, 14 lines of code related to TIFF/JP2 display resolution
3. apps/image/image_out.cpp (that reads in a JP2 and writes out a TIFF), beginning at line 1866, 14 lines of code related to JP2/TIFF display resolution
Beginning with Kakadu version 5.1.0, released 2006/11/10, kdu_compress and kdu_expand automatically support display resolution metadata using TIFF tags and JPEG2000 boxes.
I notice that using GDAL 1.7.3, released 2010/11/10, with gdal_translate -of GTiff in.tif out.tif, when in.tif includes TIFF tags 282, 283, and 296, then out.tif also includes tags 282, 283, and 296. This is good.
However, when gdal_translate reads in a TIFF, writes out a lossless or reversibly compressed JP2, using JP2KAK and JPEG2000, and then gdal_translate reads in that JP2, and writes out a TIFF, then tags 282, 283, and 296 are missing from the final .tif file, and I suspect the .jp2 file written by gdal_translate does not contain a JP2 Display Resolution Box.
gdal_translate -of JP2KAK -co QUALITY=100 in.tif out_gdal_173_JP2KAK.jp2
gdal_translate -of GTiff out_gdal_173_JP2KAK.jp2 out_gdal_173_JP2KAK.tif
gdal_translate -of JPEG2000 -co QUALITY=100 in.tif out_gdal_173_JPEG2000.jp2
gdal_translate -of GTiff out_gdal_173_JPEG2000.jp2 out_gdal_173_JPEG2000.tif
I suggest consideration be given to adding in gdal_translate support for display resolution metadata
1. when reading from .tif and writing to .jp2
2. when reading from .jp2 and writing to .tif