Bug 429219 - MWG "Applied To" state (mwg-rs:AppliedToDimensions XMP tag) is not included when writing Face metadata to file - Use ExifTool
Summary: MWG "Applied To" state (mwg-rs:AppliedToDimensions XMP tag) is not included w...
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Metadata-ExifTool (show other bugs)
Version: 7.2.0
Platform: Microsoft Windows Microsoft Windows
: NOR normal
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-11-17 01:36 UTC by José Oliver-Didier
Modified: 2021-11-15 07:01 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 7.4.0
Sentry Crash Report:


Attachments
Example Files (466.16 KB, application/x-zip-compressed)
2021-01-31 13:44 UTC, José Oliver-Didier
Details
Sample - Expected XMP metadata tag (8.88 KB, text/xml)
2021-02-10 17:31 UTC, José Oliver-Didier
Details

Note You need to log in before you can comment on or make changes to this bug.
Description José Oliver-Didier 2020-11-17 01:36:54 UTC
SUMMARY
MWG mwg-rs:AppliedToDimensions XMP tag is not included when writting Face metada to file. These values are important in determining if the face regions are valid for the image.

STEPS TO REPRODUCE
1. Using a photo with a face, scan for face.
2. Add name details to face region.
3. Write face metadata to image file.

OBSERVED RESULT
Using a metadata extraction tool such as exiftool, extract XMP.
Example: exiftool <filename> -xmp -b > output.xml

Face data is added within mwg-rs:Regions 
mwg-rs:AppliedToDimensions XMP tag with image height and width dimensions are not included.


EXPECTED RESULT
- Per MWG (Metadata Working Group) Guidelines for Handling Image Metadata version 2.0 page 53 - the mwg-rs:AppliedToDimensions field should contain "Width and height of the image at the time of processing when storing image region
metadata."
- Why is this important/useful? When an image is cropped, rotated and/or resized using an application which does not re-adjust the MWG file regions the regions risk being offset. An application can compare the recorded mwg-rs:AppliedToDimensions with the actual image dimensions to determine if the face regions are valid or not.
- In the event that the AppliedToDimensions and actual image dimensions do not match, Digikam may choose to ignore/invalidate the face regions so they can be re-applied.
- In the event an image is resized, cropped or rotated, Digikam should adjust the image regions accordingly and reset the AppliedToDimensions value.
- Another risk is that an application which does read MWG regions may ignore the face regions added by Digikam, based on the assumption that these are invalid or do not adhere to the MWG guidelines.

Refer to Page 55:

“Applied To” State
Since the file may be modified by actors that are either non-compliant to this guidance or choose not
to participate in image region metadata, it is critical to retain information about what the state of the
image was when the region was specified. A Creator MUST store the region “applied to” width and
height.
A Changer MUST update the “applied to” value upon a resize, crop, or physical rotation in order to
ensure that the region information is still valid for the new state of the file. In the case of a crop or
physical rotation, a Changer MUST also update the region coordinates so as to further ensure that the
region information remains valid. A Changer SHOULD remove region information for regions that are
no longer applicable (e.g. a region that was orphaned due to a crop or rotation operation).
A Consumer MUST validate the current state of the image and compare this against the “applied to”
state to ensure that the region information is up-to-date. The information specified in the region MUST
be validated to ensure that the data is applicable to the current state of the file. In the case where the
“applied to” size and actual image size differ, if the ratio is significantly different a Consumer SHOULD
ignore the region. Otherwise a Consumer or Changer MAY update the region metadata as though
the image were scaled to the new dimensions.


SOFTWARE/OS VERSIONS
Windows: 10
macOS: 
Linux/KDE Plasma: 
(available in About System)
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
References:
https://www.exiv2.org/tags-xmp-mwg-rs.html
Comment 1 José Oliver-Didier 2021-01-31 13:44:21 UTC
Created attachment 135332 [details]
Example Files

Adding example files:

1. Einstein.jpg is a 800x1050 image with MWG regions applied. AppliedTo dimensions are h=1050 and w=800.
2. Einstein_cropped.jpg is Einstein.jpg cropped to 534x700 with an application which does not correct the AppliedTo settings. AppliedTo remain at h=1050 and w=800, thus indicating an invalid MWG.

Suggested Digikam behavior when an invalid MWG is encountered:
1. Read the names of the MWG face tags and add them to People tags- as the face names may still be valid information and should not be lost on crop.
2. Do not apply the face regions encountered in the file metadata, as they are likely invalid.
3. Re-apply face detection/recognition so that the user can correct the face region.
Comment 2 caulier.gilles 2021-02-10 16:03:00 UTC
This report is open for 7.1.0 release. It can be reproduced with current 7.2.0 pre release ?

https://files.kde.org/digikam/

Gilles Caulier
Comment 3 José Oliver-Didier 2021-02-10 16:18:01 UTC
Yes, I can reproduce it on 7.2.0-rc (ffbcb5f3)
Comment 4 José Oliver-Didier 2021-02-10 17:31:31 UTC
Created attachment 135563 [details]
Sample - Expected XMP metadata tag

Adding sample XMP file on the expected MWG XML structure. XMP extracted from jpg using exiftool and created mwg from MS People Tag using method described here: https://jmoliver.wordpress.com/2017/02/19/converting-and-exporting-windows-photo-gallery-people-tags/

Note "AppliedToDimensions" tag:
 
   <mwg-rs:AppliedToDimensions rdf:parseType='Resource'>
    <stDim:h>1050</stDim:h>
    <stDim:unit>pixel</stDim:unit>
    <stDim:w>800</stDim:w>
   </mwg-rs:AppliedToDimensions>
Comment 5 José Oliver-Didier 2021-08-01 14:53:12 UTC
Since Exiftool support has been introduced to Digikam in 7.3.0, could Exiftool be used to read as well as write these tags to file when Face Regions are edited?

Exiftool Ref: https://exiftool.org/TagNames/MWG.html#Regions
Comment 6 caulier.gilles 2021-08-03 07:38:00 UTC
yes, sure ExifTool can used for this task, if Exiv2 is not able to do it as well. The digiKam Exiftool CC+/Qt interface that we write in digiKam core is designed to be extendable for this kind of use.

Gilles Caulier
Comment 7 Maik Qualmann 2021-08-03 11:12:52 UTC
Exiv2 already supports the AppliedToDimensions tag.

Maik
Comment 8 Maik Qualmann 2021-11-13 20:04:58 UTC
*** Bug 445440 has been marked as a duplicate of this bug. ***
Comment 9 erty 2021-11-14 09:54:56 UTC
As I described in Bug 445440, this issue also prevents the correct import of face tags into Lightroom. Because Lightroom considers mwg-rs without dimensions information invalid.
I've made many tries and that's the only reason.
Comment 10 Maik Qualmann 2021-11-14 13:19:27 UTC
Git commit 8f9bb6617460fd337ab2657b1c76a3e5421fa448 by Maik Qualmann.
Committed on 14/11/2021 at 13:15.
Pushed by mqualmann into branch 'master'.

add write mwg-rs:AppliedToDimensions XMP tag structure
Note: digiKam itself still ignores AppliedToDimensions when importing.
Related: bug 445440
FIXED-IN: 7.4.0

M  +2    -2    NEWS
M  +5    -3    core/libs/fileactionmanager/metadatahub.cpp
M  +1    -1    core/libs/metadataengine/dmetadata/dmetadata.h
M  +34   -2    core/libs/metadataengine/dmetadata/dmetadata_faces.cpp

https://invent.kde.org/graphics/digikam/commit/8f9bb6617460fd337ab2657b1c76a3e5421fa448
Comment 11 José Oliver-Didier 2021-11-14 23:19:21 UTC
This is great news! Lack of this tag had me worried for proper support of MWG Face Regions.  However, how will Digikam manage images with invalid AppliedToDimensions? When opening the bug I stated:

"In the event that the AppliedToDimensions and actual image dimensions do not match, Digikam may choose to ignore/invalidate the face regions so they can be re-applied."

What I mean with that statement is that if an image is cropped using another application which cannot adjust the face regions accordingly, the existing face regions should be ignored but the People's names should be respected so that it can be easier to re-tag them later within Digikam.
Comment 12 Maik Qualmann 2021-11-15 07:01:53 UTC
digiKam will definitely ignore the absence of the AppliedToDimensions tag. If a user had to restore their database, all of the face regions made so far would not be restored. That's why I find the Lightroom behavior very strange. If the AppliedToDimensions tag is available, we can include it, I will implement it soon.

At the moment I don't know whether the image orientation has to be ignored with the AppliedToDimensions tag and how other programs behave. Since we still do not know the orientation for which the face regions were saved. 

Maik