Structured tags with (missing) optional elements

Started by Mac2, September 28, 2014, 09:32:07 AM

Previous topic - Next topic

Mac2

I'm working with files which contain region info (faces, focus) in the -xmp-mwg-rs tag group. A file may contain multiple focus/face records, and sometimes one or more of the optional tags are missing (e.g. the name or the description of a face annotation).

How does ExifTool deal with such cases? For example, we have 5 faces, but only face 1, 3 and 5 have a description. The output looks like this:


Region Area X       : 0.112967, 0.296684, 0.479332, 0.638019, 0.799610
...
Region Description  : Desc1, Desc3, Desc5
Region Name         : Name1, Name2, Name3, Name4, Name5
Region Type         : Face, Face, Face, Face, Face


There is no way to tell from the output to which of the 5 faces the descriptions belong. It can, using the -struct argument to force structured output, but that has other consequences as well. It can get even worse, e.g.


Region Area X       : 0.112967, 0.296684, 0.479332, 0.638019, 0.799610
...
Region Description  : Desc1, Desc3, Desc5
Region Name         : Name2, Name3, Name4
Region Type         : Face, Face, Face, Face, Face

5 area records in the list, but only 3 optional descriptions and 3 optional names, but for other different areas...bugger.

Is there a way to emit 'null' values for the missing arguments, e.g.

Region Description  : Desc1, (null), Desc3, (null), Desc5

Furthermore, when writing structured tags (I only care for regions at this time) in flattened form, is there a way to write a null value in order to retain the proper sequence with missing optional tags?

Phil Harvey

There is no way to get ExifTool to emit null entries for the flattened tags.  With flattened tags it unfortunately is not possible to figure out the original associations for complex structures.  (To emit nulls would be rather complex I think.  If it were easy, I would seriously consider implementing it.  But what do you do about structure fields that don't appear in any of the structures?  Do you emit all nulls?  If not, then you need to parse the list of structures at least twice to figure out what you want to emit.  But when ExifTool reads the file it flattens the structures in the first pass, so this would need to be changed.)

To insert empty fields, I suggest setting them to a single space (" ").  This will work unless they are some sort of formatted value or controlled vocabulary, in which case you would need to use some other dummy value appropriate to the specific tag.

Dealing with structures is tricky, and very few people actually need to do this with the amount of control that you require.  I don't have much time right now, but I'll make a note of this and see if there are anything I can improve to make this easier.

- 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 ($).

Mac2

Thanks, Phil.

So far I only worked with importing flattened tags in a database using the XML output format (-X). It seems I now need to make a second pass on every file (and/or sidecar file) to import specific tags in structured form too. I foresee performance issues because often the images have several hundred MB (PSD/TIFF/DNG) and are on network storage...

Or is there a way to get the tags in flat form and structured form in one -execute?

I mean only the structured tags are emitted twice, once in their flat form and then again in their structured form. The resulting tag names are different so they should not clash...


Phil Harvey

Quote from: Mac2 on September 29, 2014, 04:05:49 AM
Or is there a way to get the tags in flat form and structured form in one -execute?

Try this:

exiftool -struct -api struct=2 FILE

:)  (bet you didn't expect that ExifTool could do that...)

If you are using the XML output format (or JSON), you should probably drop the -struct option (because it isn't necessary for these, and will affect the output for List-type 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 ($).

Mac2

#4
Well, now, this looks promising. Thank you very much  ;D
Should be simple to adapt my XML parsing code to handle this new input. For write-back I'll use the structured tags as outlined in your separate documentation. This enables me to properly handle empty optional tags for writing. Great, back to work.

Quote:)  (bet you didn't expect that ExifTool could do that...)

ExifTool never ceases to amaze me. I already know quite a bit about it, but there is still so much to learn  ;)

PH Edit: Added link to Structured Information documentation