de-duplicate resolution metadata

Started by mwarin_hathi, September 20, 2024, 01:08:35 PM

Previous topic - Next topic

mwarin_hathi

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.

StarGeek

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.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

mwarin_hathi

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

StarGeek

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 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.  From the docs on the -X (-xmlFormat) option
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.

"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

mwarin_hathi

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.

StarGeek

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.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

mwarin_hathi

Sure. Attaching a sample .jp2 with the issue.

StarGeek

Looking at the file using the -v3 (-verbose3) option, 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, 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                                              [.]
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

mwarin_hathi

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!

Phil Harvey

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
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).