News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

Picasa.ini to XMP-mwg-rs/XMP-MP Region tags

Started by StarGeek, March 03, 2015, 05:16:54 PM

Previous topic - Next topic

StarGeek

Sorry for delay in getting back to this.

Sounds like it's all nice and shiny now.

I created a new Picasa database and dropped in about 1,500 files that had the region tags already inserted.  There wasn't any obvious errors in how Picasa read the tags in and I even found one case where I had named something incorrectly, so it helped me fix an error.  So that makes me even more confident that the math is correct, not that I was very worried about it in the first place.  Looks like it's ready for real use.

I've downloaded you newest copy and I'll be giving it some heavy usage today.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

Glad to hear, because I've included it in the production ExifTool 9.90 release issued this morning. :)

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

milchtaich

This works beautifully, with one exception: RAW files in portrait orientation.
The root of the problem is the exception Picasa makes for RAW files that, according to the Exif Orientation tag, need to be rotated. In any other case, the origin of the image is the top-left corner of the stored, unrotated image. This is in accordance with the MWG standard, so everything is good. However, for some reason, for RAW files Picasa views the top-left corner of the rotated image as the origin, and computes the coordinates stored at the INI file accordingly. This creates a problem when the -RegionInfo<PicasaToMWGRegion command is used for writing the MWG area information to an XMP sidecar. Lightroom 6 reads the information off that file and draws the rectangle at the wrong place, even though it exactly follows the standard.
This error may be prevented by changing the logic of the command to accommodate Picasa's peculiarity described above when dealing with RAW files whose orientation is not Horizontal.

Igal Milchtaich

StarGeek

Shame on me for not testing rotated images (one of my first steps is to losslessly rotate my jpgs).   And shame on me for assuming that Picasa will do the right thing in the first place.

I'm pretty sure that Picasa doesn't read region data from NEF or CR2 so any fix can ignore what Picasa does and just write correct data. 

It's cool that LR6 is reading region data.  Does it read it if it's embedded in the file or only from external xmp? 

Am I correct in thinking that this is what's required to rotate a region?
Rotate 90
X=1-H-Y
Y=X
Swap Width and Height.

Rotate 180
X=1-W-X
Y=1-H-Y
(no change to W and H)

Rotate 270
X=Y
Y=1-W-X
Swap Width and Height.

I did some quick checking and couldn't see any details on how Microsoft regions dealt with image orientation.

* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

milchtaich

@StarGeek,
Lightroom 6 reads MWG region information from JPGs, RAW files and XMP sidecars of RAW files. This is indeed an exciting development that makes your work timely and valuable to many photographers. Note that the problem I described only concerns RAWs. JPGs are not affected, regardless of their orientation.

The corrections that need to be applied I believe are the following. (The left-hand side are the corrected values, those used on the right-hand side are the uncorrected ones – the current output of -RegionInfo<PicasaToMWGRegion).

Rotate 90
X=Y
Y=1-X
Swap Width and Height.

Rotate 180
X=1-X
Y=1-Y
(no change to W and H)

Rotate 270
X=1-Y
Y=X
Swap Width and Height.

Microsoft lives in a fool's paradise: it completely ignores orientation. In the present context, this is good. One thing I noticed at the time was that their published specification did not match their practice. In the Rectangle quartet, the first and second entries are respectively the x and y coordinates of the top-left corner of the rectangle (rather than the reverse order, y and x) and the third and fourth entries are respectively the W and H of the rectangle (rather than H and W, in that order, which is what the http://ns.microsoft.com/photo/1.2/ scheme specifies). However, I do not work with the Microsoft scheme and did not try the -RegionInfoMP<PicasaToMPRegion command, so this observation should be taken with a grain of salt.

Igal Milchtaich 

StarGeek

Sorry it took so long to get back to this.

I think I have this corrected now, but only for NEF and CR2 at the moment, since those are the only raw file types I have on hand at the moment.  I plan on looking for other raw file types that Picasa supports and if anyone has a rotated one where Picasa detects a face and is willing to share, it'd be appreciated.

It's only had limited testing so far, so use at your own risk.  I also don't have LR6 so I can't see if that's going to be correct.  I had to compare the results from the raw files to the corresponding jpg.  Also I didn't deal with the more unlikely orientations such as Mirror vertical or Mirror horizontal.

Additionally, I created a config file that can be used to rotate the regions in a file.   These are RotateMWGRegionCW90 (or 180/270) and RotateMPRegionCW90 (or 180/270).  The commands for those would be exiftool -config Rotate_Regions.config "-RegionInfo<RotateMWGRegionCW90" FILE or something similar.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

This is great, thanks!

I've cleaned up the picasa_faces.config file a bit.  Let me know what you think.

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

milchtaich

The latest, 2015/05/12 version of picasa_faces.config works well also for Sony ARW files (as does the 2015/05/11 version, with this file type added to RawFileTypes), with images rotated 0°, 90° or 270°. Very nice!

More often than not, Lightroom 6 reads the region data that ExifTool writes to the sidecar XMP files and shows the face rectangles and names. Why it doesn't always do so I don't know, but my suspicion is that the problem is something else than the region metadata. The whole face tagging business in LR is a work in progress.

StarGeek

#38
I just tested a DNG and verified that it needs to be on the isRawFile list.  So that means that CRW, ERF, MEF, MRW, NRW, ORF,  SRW, and  X3F are untested.  Though in all probability they will need to be on there.

Edit: Found a PEF.  Its EXIF was a bit messed up but after fixing that, it worked properly with the new config.  I'll keep looking around until I catch 'em all.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

StarGeek

#39
Thanks to user Evds for pointing out a problem with this.

Due to the nature of floating point numbers, sometimes the Height and Width variables end up being extremely long, for example, something like 0.0567941000000001.  There seems to be a limit to how large a number that Picasa will read in and it will not reload regions with long decimals like this.

The fix is easy though.  Lines 153 and 154 need to be changed from
                W => $x1 - $x0,
                H => $y1 - $y0,


to
                W => int(($x1 - $x0)*10000000+.5)/10000000,
                H => int(($y1 - $y0)*10000000+.5)/10000000,


edit: Too many parens, fixed.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

Great.  I'll make this change in the distributed config file.

Thanks.

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

StarGeek

#41
A minor adjustment to the code for this config file.  I finally took time to figure out exactly the degree of precision that Picasa would start ignoring regions.  If the regions were 10 decimal places or greater, then the regions would not be applied.  So here's my suggestion on changes to lines 144 to 154.  The comment has been moved, the earlier rounding operations have been moved, and the rounding precision extended from 7 decimals to 9 decimals.
            my $x0 = ($hi >> 16)   /65535;
            my $y0 = ($hi & 0xffff)/65535;
            my $x1 = ($lo >> 16)   /65535;
            my $y1 = ($lo & 0xffff)/65535;
            push @{ $fileHash{$section} }, {
                ContactID => $2,
# round to 8 decimals (Picasa will ignore regions with greater than 10 decimals)
                X => int($x0*100000000+.5)/100000000,
                Y => int($y0*100000000+.5)/100000000,
                W => int(($x1 - $x0)*100000000+.5)/100000000,
                H => int(($y1 - $y0)*100000000+.5)/100000000,,


Edit:  Changed to 8 decimals instead of 9.  Division in lines 216-217 can increase in number of decimals.

Edit 2:  Upon further thought, it might be best to move all rounding operations to the final assignment of values.  I think the RotateRegion sub has the possibility of introducing a precision problem as well.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

Great, thanks.  This update will appear in the next release.

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

StarGeek

One (hopefully) final update to this config.  The rounding operation has been moved to a subroutine, so you don't need to search throughout the config if you want to make adjustments.  Rounding is now made after all the math operations are done, so there should be no more chance of floating point errors.  Precision increased to max that Picasa can use.  No real point to this as the difference won't amount to even a pixel in size unless your image is tens of thousands of pixels wide/high, but then again, why not.

I've done only limited testing, using 20 images that had precision problems under previous versions, and those came out correctly. 

On regular camera images, this seems to be a very rare error.  I checked some of my pictures I used the older config on and out of a little over 93,000 images that I had tagged, only 586 pictures had this error.

However, on random images I had downloaded from the net, the error margin seemed much higher, maybe about 5%.  Though those are much more varied in image dimensions, so that may have something to do with it.


The second attached config file will correct rounding errors on previous images.  It includes the tags CorrectedMPRegion and CorrectedMWGRegion which can be redirected into RegioninfoMP and Regioninfo.  The command I'm using to fix previous errors is this:
exiftool -config Correct_Region.config -struct -if "$CorrectedMWGRegion or $CorrectedMPRegion" "-RegionInfo<CorrectedMWGRegion" "-RegionInfoMP<CorrectedMPRegion" DIR
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Phil Harvey

Great, thanks.  The updated config file will appear in the next release.

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