managing (IPTC) regions

Started by eesger, May 14, 2021, 04:53:40 PM

Previous topic - Next topic

eesger

I am working on a proof of concept for managing and structuring my massive image database into mysql and build an interface around it.. but I also want to make it robust, by storing the image data into the images..
I am planing to use the IPTC structure to store that and it appears that exiftool is the only one that can handle 'regions' in a decent way..

But, with the data in multiple fields I am having trouble wrapping my head around getting the data out (and in!) the right way..

I was hoping to get a json structure where the image region info is bundled and not separate.. especially when multiple shapes are used (circle, polygon, rectangle) it gets a bit messy for my taste.

The only way I found out so far is to use this to get "combined data":
exiftool -struct photo-4iptc-heads.jpg

Also I'dd like to be able to update/add/remove a region..

Some pointers into the right direction will be much appreciated

PS: I am proficient in perl and I think it'll be easiest to build "the connection" in perl.. but tips in commandline or via PHP are also welcome

StarGeek

Quote from: eesger on May 14, 2021, 04:53:40 PM
I am planing to use the IPTC structure to store that and it appears that exiftool is the only one that can handle 'regions' in a decent way..

Personally, I would suggest using the MWG regions, as that standard has much wider support.  It's used by Lightroom, Digikam, and Imatch, and while ACDSee doesn't support it directly, it does have the ability to read MWG regions and convert them to their own format.

I'm not sure if there's any program available that has support of IPTC regions, other than exiftool.

And there is always the option of using both, as exiftool's convert_regions.config file can convert between the two.

QuoteI was hoping to get a json structure where the image region info is bundled and not separate.. especially when multiple shapes are used (circle, polygon, rectangle) it gets a bit messy for my taste.

The only way I found out so far is to use this to get "combined data":
exiftool -struct photo-4iptc-heads.jpg

Yes, the -struct option is the only way to get region data all at once and properly set up.  See the Structured Information page.  But you can combine it with the -j (-json) option
C:\>exiftool -json -struct -regioninfo y:\!temp\Test4.jpg
[{
  "SourceFile": "y:\!temp\Test4.jpg ",
  "RegionInfo": {
    "AppliedToDimensions": {
      "H": 2336,
      "Unit": "pixel",
      "W": 3504
    },
    "RegionList": [{
      "Area": {
        "H": 0.3758603,
        "Unit": "normalized",
        "W": 0.2086213,
        "X": 0.44563975,
        "Y": 0.28339055
      },
      "Name": "Jerry Smith",
      "Type": "Face"
    },{
      "Area": {
        "H": 0.2893721,
        "Unit": "normalized",
        "W": 0.1606622,
        "X": 0.6522545,
        "Y": 0.45590905
      },
      "Name": "Beth Smith",
      "Type": "Face"
    }]
  }
}]


And to re-embed the data
exiftool -json=region.json y:\!temp\Test4.jpg
though if you wanted to copy the data from the json to a new image, then the SourceFile entry in the json would have to be edited or removed.  See second paragraph under the -json option.

QuotePS: I am proficient in perl and I think it'll be easiest to build "the connection" in perl
Something that might help is to realize that the raw data output by adding the -struct option is almost exactly the same as would be output by using Data::Dumper.  Internally, exiftool holds the data as a hash of hashes/arrays.

"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

eesger

Thank you for the reply.

I use IrfanView a lot, that one can show/edit EXIF and IPTC, so I assumed IPTC was 'the standard', I haven't committed to anything yet, so if 'MWG' is better, I'll go for that one.

If I may ask a few more questions:

  • Is MWG the same as XMP?
  • Can the different standards co exist in one file? (like EXIF / IPTC / MWG)
  • When exiftool edits/adds meta data, is the original file date maintained?
  • Does exiftool check if the edited file is correct? (there is no risk of data corruption?)
  • Can I find an 'MWG example file' somewhere?
  • Can I update a single value? (with regions, do I need to update the entire set, or could I also update/add one region?)
  • Are there some simple "region mod/add/remove examples" in Perl somewhere?


StarGeek

Quote from: eesger on May 17, 2021, 05:02:20 AM
I use IrfanView a lot, that one can show/edit EXIF and IPTC, so I assumed IPTC was 'the standard', I haven't committed to anything yet, so if 'MWG' is better, I'll go for that one.

Irfanview displays the older IPTC IIM/Legacy standard, which was created in the early 1990s. This is different than the more modern IPTC Core/Ext standard, which is XMP based.  The IPTC IIM/Legacy "technically" has character limits on all its tags.  For example, an IPTC:Keywords cannot be longer than 64 characters according to the spec.  But there are very few programs that obey this part of the spec.  Exiftool will enforce it by default, you'll get warning of Warning: [Minor] TAGNAME exceeds length limit (truncated), but this can be overridden with -m (-ignoreMinorErrors) option.

I use Irfanview as well and because it doesn't support XMP, even though support for it has been requested for over a decade, I end up having to sync my data between IPTC IIM and XMP.  If Irfanview ever gets XMP support or I find a image viewing program that compares well to Irfanview, I'll be dropping IPTC.

QuoteIs MWG the same as XMP?

MWG regions are a subset of XMP (see XMP tags, as well as other groups on the tag names page). Because XMP is so flexible and expandable, there are many, many sub-categories.  Some companies, such as ACDSee, make their own subset even though there are existing standards that serve the same purpose.  Even Victoria's Secret, the lingerie company, has their own set of XMP tags.

QuoteCan the different standards co exist in one file? (like EXIF / IPTC / MWG)

Yes.  Off hand, I can't think of any type of image metadata that will conflict with another type, as long as it can be put into the image.  But not all types of data can go into all images (see Supported file types table).  For example, BMP files cannot hold any metadata.  GIF files can hold XMP, but nothing else.  PNG gained the ability to hold EXIF data only a few years ago and IPTC IIM data in a PNG is non-standard.

QuoteWhen exiftool edits/adds meta data, is the original file date maintained?

I'm guessing you mean the file system timestamps?  The FileCreateDate is preserved on Windows.  I'm not sure on the Mac, as I believe some of the Mac's MD tags will be lost unless the -overwrite_original_in_place option is used.

The FileModifyDate will be changed to the current time because, obviously, the file has been modified.  That can be prevented by using the -P (-preserve) option (capital P, lowercase p is a different option).

QuoteDoes exiftool check if the edited file is correct? (there is no risk of data corruption?)

Exiftool doesn't compare the old file to the new one if that's what you mean.  You can see details about how it works on the Under the hood page.  But basically, whenever exiftool edits embedded data, it makes a new copy of the file with the edits.  If that file is created successfully, no errors or problems with the original file's formatting, then the original file is renamed by adding _original to the end and the new file is renamed to the original name.  The -overwrite_original and -overwrite_original_in_place option will alter this behavior.  Non-embedded tags, such as the filesystem permissions and timestamps, do not cause the creation of a new file.

QuoteCan I find an 'MWG example file' somewhere?

You can create one by copy/saving the json I listed above, removing the SourceFile line, and running the command listed.  Also, you can check the image attachments in the ACDSee region threads (here and here) as some of the images in those threads have MWG regions, as well as other types of regions.

QuoteCan I update a single value? (with regions, do I need to update the entire set, or could I also update/add one region?)

Technically, you can to a degree.  For example, I use this command to change region names if I misspell a name or otherwise need to change a name.
exiftool -P -overwrite_original -progress -if "$RegionName ne $RegionName# or $RegionPersonDisplayName ne $RegionPersonDisplayName#" -TagsFromFile @ -RegionName -RegionPersonDisplayName -api "Filter=s/old name/new name/i"

But things can go wrong when using flattened tags like this (see the struct page link above for details).  For example, if you have three regions, but one of them doesn't have a name, the flattened tags don't have an option for skipping that entry.

Basically, it's safer to use the full structure if you can.

QuoteAre there some simple "region mod/add/remove examples" in Perl somewhere?

I don't believe so.  I do everything through the command line and I don't believe there's a large number of people creating custom Perl scripts.
"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

eesger

Thanks again for your response.

exiftool -P -overwrite_original -progress -if "$RegionName ne $RegionName# or $RegionPersonDisplayName ne $RegionPersonDisplayName#" -TagsFromFile @ -RegionName -RegionPersonDisplayName -api "Filter=s/old name/new name/i"
If I need a nifty exiftool oneliner, I know who to ask! (I expected a variable to be something like $RegionInfo_RegionList_Name.. where do you find the variable names?)

Is 'AppliedToDimensions' an obligatory dataset? It seems rather superfluous?

Is area (with X/Y and H/W) the only option for XMP-tagging? Is a circle also possible and a polygon (as with the IPTC regions)?
And "Type", is that a "free field", I can place in that what I want; like face, car, building etc, or is there a fixed set of values?

StarGeek

Quote from: eesger on May 19, 2021, 10:40:11 AM
If I need a nifty exiftool oneliner, I know who to ask! (I expected a variable to be something like $RegionInfo_RegionList_Name.. where do you find the variable names?)

You can find all 24,273 tags names on the Tag Names sub-pages.  There are many cases where tag names have been shortened or changed to make things easier or more obvious.  The details can be found in the "Notes" columns for the individual tags. In this case, the base name is "Region" which was changed to RegionInfo and the full name would have been "RegionsRegionListName", reduced to just RegionName.  See MWG Regions tags.

QuoteIs 'AppliedToDimensions' an obligatory dataset? It seems rather superfluous?

That was my thought when seeing it. The specs list it as "Width and height of the image at the time of processing when storing image region metadata."  Things like that happen with a lot of specs.  For example, the EXIF spec has two mandatory tags like this, ExifImageWidth and ExifImageHeight.  And ACDSee regions, which are basically a copy of the MWG Regions spec, also have the "AppliedToDimensions" entries.

As to whether they are required, I guess that depends upon the program reading the data.  My copy of Lightroom is old and doesn't have the ability to read regions so I can't test that.  I also use IMatch, which does use MWG regions and I have noticed that in the case of CR2 files, it writes what exiftool lists for the PreviewImage image dimensions instead of the RAW image dimensions and has no problem with it.  The fact that the region data is based upon a percentage of the image dimensions instead of exact pixel dimensions makes that easier to deal with in cases where the "AppliedToDimensions" data is inaccurate.  Page 51 of the Metadata Working Group's Guidelines goes into some of the details of possible problems with region data and is worth reading.

QuoteIs area (with X/Y and H/W) the only option for XMP-tagging?  Is a circle also possible and a polygon (as with the IPTC regions)?

For MWG regions, yes, it appears to be. IPTC regions are the only one that gives options for the shape.  It should be noted that all region data, MWG, Microsoft, IPTC, and ACDSee regions, are all XMP.

QuoteAnd "Type", is that a "free field", I can place in that what I want; like face, car, building etc, or is there a fixed set of values?

Technically, it appears to be a limited set.  The MWG spec lists it as a "Closed Choice" with options of Face, Pet, Focus, and BarCode.  But I don't think any software supports choices in this to begin with.

It just my opinion, but the IPTC regions are the Betamax/HD DVD to MWG regions VHS/Bluray.  MWG regions have widespread support in programs and have been out for about 10 years or so.  IPTC regions are less than 2 years old and I haven't come across a single program that can read them.

But with exiftool, you can always convert between the two using the config file I linked above.
"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