ExifTool Forum

General => Metadata => Topic started by: mwarin_hathi on September 20, 2024, 01:08:35 PM

Title: de-duplicate resolution metadata
Post by: mwarin_hathi on September 20, 2024, 01:08:35 PM
I have received a JPEG2000 whose resolution data are causing issues further downstream.

$ exiftool -X *00000001.jp2 | grep -i resolution
 <Jpeg2000:CaptureYResolution>118.1102</Jpeg2000:CaptureYResolution>
 <Jpeg2000:CaptureXResolution>118.1102</Jpeg2000:CaptureXResolution>
 <Jpeg2000:CaptureYResolutionUnit>cm</Jpeg2000:CaptureYResolutionUnit>
 <Jpeg2000:CaptureXResolutionUnit>cm</Jpeg2000:CaptureXResolutionUnit>
 <Jpeg2000:CaptureYResolution>1.181102</Jpeg2000:CaptureYResolution>
 <Jpeg2000:CaptureXResolution>1.181102</Jpeg2000:CaptureXResolution>
 <Jpeg2000:CaptureYResolutionUnit>0.1 mm</Jpeg2000:CaptureYResolutionUnit>
 <Jpeg2000:CaptureXResolutionUnit>0.1 mm</Jpeg2000:CaptureXResolutionUnit>


The code downstream can't tell which resolution value goes with which resolution unit,
i.e. that CaptureXResolution:1.181102 should go with CaptureXResolutionUnit:cm and not CaptureXResolutionUnit:0.1 mm.
Trying to edit any of the resolution tags is unsuccessful:

Warning: Sorry, Jpeg2000:CaptureXResolutionUnit doesn't exist or isn't writable


Can I get exiftool to de-duplicate these for me somehow, and just give me one set of values and their corresponding (correct) unit?

I realize I can (and might have to) write a "resolution parser" to fix this for me, but if there is exiftool-magic I can use that might be better.

Any help appreciated, total image noob here.
Title: Re: de-duplicate resolution metadata
Post by: StarGeek on September 21, 2024, 01:45:38 PM
Please use this command to list the data (assuming Mac/Linux), and copy/paste all of it here
exiftool -G1 -a -s '-*resolution*'  *00000001.jp2

Without these options, some of the data isn't showing and using grep sometimes removes some needed data.
Title: Re: de-duplicate resolution metadata
Post by: mwarin_hathi on September 23, 2024, 10:10:46 AM
Hi StarGeek, sure thing:

$ exiftool -G1 -a -s '-*resolution*'  *00000001.jp2
[Jpeg2000]      CaptureYResolution              : 118.1102
[Jpeg2000]      CaptureXResolution              : 118.1102
[Jpeg2000]      CaptureYResolutionUnit          : cm
[Jpeg2000]      CaptureXResolutionUnit          : cm
[Jpeg2000]      CaptureYResolution              : 1.181102
[Jpeg2000]      CaptureXResolution              : 1.181102
[Jpeg2000]      CaptureYResolutionUnit          : 0.1 mm
[Jpeg2000]      CaptureXResolutionUnit          : 0.1 mm

Also:
$ exiftool -ver
12.76

$ lsb_release -a
Description: Ubuntu 24.04.1 LTS
Release: 24.04
Title: Re: de-duplicate resolution metadata
Post by: StarGeek on September 23, 2024, 11:49:56 AM
I don't really have any experience with jpeg2000 files, so I don't know why these tags are duplicated with basically the same values at different scales.

Checking the Jpeg2000 tags page (https://exiftool.org/TagNames/Jpeg2000.html#CaptureResolution) nearly all of them are not writable, so exiftool isn't something that could fix the file with regards to the duplicated tags.

You might try adding the -s (-short) option (https://exiftool.org/exiftool_pod.html#s-NUM--short).  From the docs on the -X (-xmlFormat) option (https://exiftool.org/exiftool_pod.html#X--xmlFormat)
QuoteAnother restriction of -s is that only one tag with a given group and name may appear in the output.

That should limit the output, but you should probably do some testing to see if it might affect something else in the workflow.

Title: Re: de-duplicate resolution metadata
Post by: mwarin_hathi on September 23, 2024, 12:47:03 PM
We process quite a lot of Jpeg2000s, and this (seeing more than one set of resolution tags) is not generally something that happens.

Adding -s does remove one set of resolution tags, but it does not seem to do so intelligently:

$ exiftool -X -s *00000001.jp2 | grep -i resolution
 Jpeg2000:CaptureYResolution='1.181102'
 Jpeg2000:CaptureXResolution='1.181102'
 Jpeg2000:CaptureYResolutionUnit='0.1 mm'
 Jpeg2000:CaptureXResolutionUnit='0.1 mm'

My attempt at resolution parsing consists of picking the biggest unit and the smallest value, if there are multiple units/values for a given resolution tag.
Title: Re: de-duplicate resolution metadata
Post by: StarGeek on September 23, 2024, 01:20:37 PM
It is listing them in the order they appear in the file. I don't know enough about the file format to help more.

Phil may be able to shed more light on this, especially if you can make a sample file available.
Title: Re: de-duplicate resolution metadata
Post by: mwarin_hathi on September 23, 2024, 02:14:33 PM
Sure. Attaching a sample .jp2 with the issue.
Title: Re: de-duplicate resolution metadata
Post by: StarGeek on September 23, 2024, 03:24:13 PM
Looking at the file using the -v3 (-verbose3) option (https://exiftool.org/exiftool_pod.html#v-NUM--verbose), it shows that exiftool isn't mismatching the data, it's written incorrectly in the file.

The first appearance of the resolution data. If you check on the Jpeg2000 ResolutionUnit Values table (https://exiftool.org/TagNames/Jpeg2000.html#ResolutionUnit), you can see that a Capture*ResolutionUnit of 2 is centimeters. So this resolution group is set to 118.1102 cm.
  | | | CaptureResolution (SubDirectory) -->
  | | | - Tag 'resc' (10 bytes):
  | | |     005d: 75 30 00 fe 75 30 00 fe 02 02                   [u0..u0....]
  | | | + [BinaryData directory, 10 bytes]
  | | | | CaptureYResolution = 118.1102
  | | | | - Tag 0x0000 (4 bytes, rational32u[1]):
  | | | |     005d: 75 30 00 fe                                     [u0..]
  | | | | CaptureXResolution = 118.1102
  | | | | - Tag 0x0004 (4 bytes, rational32u[1]):
  | | | |     0061: 75 30 00 fe                                     [u0..]
  | | | | CaptureYResolutionUnit = 2
  | | | | - Tag 0x0008 (1 bytes, int8s[1]):
  | | | |     0065: 02                                              [.]
  | | | | CaptureXResolutionUnit = 2
  | | | | - Tag 0x0009 (1 bytes, int8s[1]):
  | | | |     0066: 02                                              [.]

The second resolution directory shows a Capture*ResolutionUnit of 4, which is 0.1 mm, resulting in 1.181102  0.1mm
| | CaptureResolution (SubDirectory) -->
  | | - Tag 'resc' (10 bytes):
  | |     0077: 01 2c 00 fe 01 2c 00 fe 04 04                   [.,...,....]
  | | + [BinaryData directory, 10 bytes]
  | | | CaptureYResolution = 1.181102
  | | | - Tag 0x0000 (4 bytes, rational32u[1]):
  | | |     0077: 01 2c 00 fe                                     [.,..]
  | | | CaptureXResolution = 1.181102
  | | | - Tag 0x0004 (4 bytes, rational32u[1]):
  | | |     007b: 01 2c 00 fe                                     [.,..]
  | | | CaptureYResolutionUnit = 4
  | | | - Tag 0x0008 (1 bytes, int8s[1]):
  | | |     007f: 04                                              [.]
  | | | CaptureXResolutionUnit = 4
  | | | - Tag 0x0009 (1 bytes, int8s[1]):
  | | |     0080: 04                                              [.]
Title: Re: de-duplicate resolution metadata
Post by: mwarin_hathi on September 24, 2024, 05:16:34 PM
Many thanks, StarGeek, I think we know enough about what is actually going on now to proceed.

Glad to see this forum being so active and helpful, love it!
Title: Re: de-duplicate resolution metadata
Post by: Phil Harvey on September 24, 2024, 05:25:27 PM
Interesting that the locations are different for these, one is in the JP2 header, and one is at the top level.  I'm not sure what that could signify:

> exiftool multi_resolution_tags.jp2 -G5 "-*resolution*"
[JP2-JP2-JP2Header-Resolution-CaptureResolution] Capture Y Resolution: 118.1102
[JP2-JP2-JP2Header-Resolution-CaptureResolution] Capture X Resolution: 118.1102
[JP2-JP2-JP2Header-Resolution-CaptureResolution] Capture Y Resolution Unit: cm
[JP2-JP2-JP2Header-Resolution-CaptureResolution] Capture X Resolution Unit: cm
[JP2-JP2-Resolution-CaptureResolution] Capture Y Resolution: 1.181102
[JP2-JP2-Resolution-CaptureResolution] Capture X Resolution: 1.181102
[JP2-JP2-Resolution-CaptureResolution] Capture Y Resolution Unit: 0.1 mm
[JP2-JP2-Resolution-CaptureResolution] Capture X Resolution Unit: 0.1 mm

As you have seen, ExifTool doesn't have the ability to write these tags.

- Phil