iipsrv icon indicating copy to clipboard operation
iipsrv copied to clipboard

XMP Metadata for JPEG2000

Open ruven opened this issue 4 years ago • 6 comments

@ruven Is there a particular reason why this feature is only available for TIFF images? (as stated in the 1.1 release annoucement). Do you plan to implement this for JPEG2000 images as well in the future?

Originally posted by @regisrob in https://github.com/ruven/iipsrv/issues/166#issuecomment-583521974

ruven avatar Feb 08 '20 13:02 ruven

@ruven I have another use case for metadata embedding in jpg tiles: I am missing image resolution info in tiles. Currently, iipsrv puts

Resolution Unit                 : None
X Resolution                    : 1
Y Resolution                    : 1

into each tile, disregarding the actual zoom level. We have jp2 source files mostly 300 dpi, but most maps are 600 dpi and some other images are somewhere in between. What we would like to do is to give our users the possibility to print the pages in original size from the imageserver generated tiles.

Currently, we allow users to download image regions using a crop tool (see this map).

The primary use-case would probably be a full resolution regions of an image, although it might be possible to calculate the resolution of any tile quite easily.

zabak avatar Feb 12 '20 22:02 zabak

In fact the resolution is not specifically set by iipsrv in the JPEG header's native metadata fields and is set by default to 1 by libjpeg. XMP metadata is a separate stream within the header, which is copied over from the source file.

So, if I've understood correctly, you want this to be set dynamically depending on the resolution of the view or tile requested? It should be easy to add this - I'll take a look.

ruven avatar Feb 17 '20 10:02 ruven

So, if I've understood correctly, you want this to be set dynamically depending on the resolution of the view or tile requested?

Yes, thanks!

zabak avatar Feb 17 '20 10:02 zabak

OK, I've just pushed a new commit (https://github.com/ruven/iipsrv/commit/3aea1fcf260db7f505d6c147834aed89f015fe02) which adds resolution info to the JPEG file, which changes depending on the zoom level you are at. For the moment, this only works for TIFF, which has a dedicated resolution metadata field.

ruven avatar Feb 17 '20 21:02 ruven

@ruven for jp2 (we do not use TIFF at all) the info on capture resolution should be stored in Resolution Box/Capture Resolution Box. It has also been discussed and resolved here: http://wiki.opf-labs.org/display/TR/Resolution+not+in+expected+header+fields According to JPEG2000 documentation Using jpylyzer I am getting this info from one of my files:

            <resolutionBox>
                <captureResolutionBox>
                    <vRcN>60000</vRcN>
                    <vRcD>254</vRcD>
                    <hRcN>60000</hRcN>
                    <hRcD>254</hRcD>
                    <vRcE>2</vRcE>
                    <hRcE>2</hRcE>
                    <vRescInPixelsPerMeter>23622.05</vRescInPixelsPerMeter>
                    <hRescInPixelsPerMeter>23622.05</hRescInPixelsPerMeter>
                    <vRescInPixelsPerInch>600.0</vRescInPixelsPerInch>
                    <hRescInPixelsPerInch>600.0</hRescInPixelsPerInch>
                </captureResolutionBox>
            </resolutionBox>

See the relevant code in jpylyzer to calculate the ppi values.

Does this help?

zabak avatar Feb 17 '20 23:02 zabak

OK, I managed to find a way to get this info from Kakadu. Try the latest commit: https://github.com/ruven/iipsrv/commit/7a8ea680b139f57a76e35ddc202c941c2c26a9c2

As listed in your link (http://wiki.opf-labs.org/display/TR/Resolution+not+in+expected+header+fields), this isn't supported in OpenJPEG at the moment, so only TIFF and JPEG2000/Kakadu will work.

ruven avatar Feb 18 '20 12:02 ruven

OK, there's now full XMP metadata support for JPEG2000 and Kakadu: https://github.com/ruven/iipsrv/commit/9854878ecde0c47269d0853763653467fe12e980

Unfortunately, this looks impossible to do currently with OpenJPEG

ruven avatar Sep 02 '22 13:09 ruven