Restore GPS date to Extracted Thermal Image

Started by mcq, May 01, 2025, 01:25:24 PM

Previous topic - Next topic

mcq

Is there way of restoring the GPS data to an image that was produced from a FLIR camera where the new image is the surface temperatures that was captured from the original image.

Using TermimageJ in ImageJ rodiometric images (pixel values are temperatures) are produced from raw images produced from a FLIR thermal camera.

Attached are the raw image (P4210892.jpg) and radiometric image (P4210892-GreyTemp.jpg).

Phil Harvey

Your raw image contains this GPS information:

> exiftool P4210892* "-gps*" -G1
======== P4210892-GreyTemp.jpg
======== P4210892.JPG
[GPS]           GPS Version ID                  : 2.3.0.0
[GPS]           GPS Latitude Ref                : North
[GPS]           GPS Latitude                    : 40.394854
[GPS]           GPS Longitude Ref               : West
[GPS]           GPS Longitude                   : 111.833105
[GPS]           GPS Altitude Ref                : Above Sea Level
[GPS]           GPS Altitude                    : 1404.853394 m
[GPS]           GPS Satellites                  : 26
[XMP-Camera]    GPSXY Accuracy                  : 0.736613898638506
[XMP-Camera]    GPSZ Accuracy                   : 1.10000002384186
[XMP-exif]      GPS Latitude                    : 40.394854 N
[XMP-exif]      GPS Longitude                   : 111.833105 W
[XMP-exif]      GPS Altitude                    : 1404.85339355469 m
[XMP-exif]      GPS Altitude Ref                : Above Sea Level
[Composite]     GPS Altitude                    : 1404.8 m Above Sea Level
[Composite]     GPS Latitude                    : 40.394854 N
[Composite]     GPS Longitude                   : 111.833105 W
[Composite]     GPS Latitude Ref                : North
[Composite]     GPS Longitude Ref               : West
[Composite]     GPS Position                    : 40.394854 N, 111.833105 W

To copy these tags (except the non-standared XMP-Camera tags) to the same locations in the radiometric image, use this command:

exiftool -tagsfromfile P4210892.JPG "-all:gps*" P4210892-GreyTemp.jpg

- 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

Exiftool can copy the tags in the GPS group and the XMP-exif group because those tags are builtin. You can use this command

exiftool -TagsFromFile P4210892.JPG -gps:all -xmp:gps* P4210892-GreyTemp.jpg

The XMP-Camera GPS tags are a problem.

The XMP-Camera tags are not built in and require the use of the  pix4d.config file. The trouble is that the config file lists GPSXYAccuracy/GPSZAccuracy as real numbers (e.g. floating point number) while your file has saved the values as rational (e.g. fractional number).

I checked the spec that is linked in the config file (through archive.org) and it looks like it is supposed to be rational.

Download the pix4d.config file and save it into the same directory as exiftool. Then open it up in a text editor (not something like Word or Google Docs). Find these two lines
    GPSXYAccuracy   => { Writable => 'real' },
    GPSZAccuracy    => { Writable => 'real' },
and change them to
    GPSXYAccuracy   => { Writable => 'rational' },
    GPSZAccuracy    => { Writable => 'rational' },

After doing that, you should be able to copy the tags with this command
exiftool -config pix4d.config -TagsFromFile P4210892.JPG -gps:all -xmp-exif:gps* -xmp-camera:gps* P4210892-GreyTemp.jpg
"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

Phil Harvey

Thanks StarGeek, I'll fix this config file in the next release.  As you can see from my comment at the bottom of this page, I was unclear about the "rational" storage format.

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

mcq

Thank you both for this great service and help.

I have a folder that has the raw images and a folder with the temperature images.

In the code you listed how do I make so that I can add the GPS data to each temperature image file from the corresponding raw file?

Raw images are in a folder "C:\Users\mquilter\Desktop\ThermalTest\Working Copies-GIMP", with images named P4######.JPG with 78 images. 

The temperature images are in "C:\Users\mquilter\Desktop\ThermalTest\Temp-Jpeg, with images named T4######.JPG. 

The corresponding images have the same name except for the raw images start with "P" and the temperature images start with "T".

Here is the code you suggested after copying the pix4d.config file into the exiftool directory:
"exiftool -TagsFromFile P4210892.JPG -gps:all -xmp:gps* P4210892-GreyTemp.jpg"

 
 

StarGeek

Quote from: mcq on May 02, 2025, 10:10:04 AMHere is the code you suggested after copying the pix4d.config file into the exiftool directory:
exiftool -TagsFromFile P4210892.JPG -gps:all -xmp:gps* P4210892-GreyTemp.jpg

If you want to include the XMP-Camera tags, you need to use my second command, not the first one.

QuoteRaw images are in a folder "C:\Users\mquilter\Desktop\ThermalTest\Working Copies-GIMP", with images named P4######.JPG with 78 images.

The temperature images are in "C:\Users\mquilter\Desktop\ThermalTest\Temp-Jpeg, with images named T4######.JPG.

The corresponding images have the same name except for the raw images start with "P" and the temperature images start with "T".

Thanks for the example. Too many people don't include that necessary detail.

Try this command and test it first to make sure
exiftool -config pix4d.config -TagsFromFile %-:1dWorking\T%.1f.%e -gps:all -xmp-exif:gps* -xmp-camera:gps* C:\Users\mquilter\Desktop\ThermalTest

Here's a break-down of the format code that follows the -TagsFromFile. For every file in the ThermalTest directory, exiftool will do this

%-:1d The %d code takes the directory of the file, in this case C:\Users\mquilter\Desktop\ThermalTest. The minus sign indicates that the edit starts at the end of the path and works backward. The colon indicates that the edit will be directories, not characters. The result is removing the last directory in the path. The final result is C:\Users\mquilter\Desktop\

Working\T This is a simple string added to the end of the %d, resulting in C:\Users\mquilter\Desktop\Working\T

%.1f The %f code is the base filename (no extension). The .1 indicates to skip the first character and return the rest of the filename. C:\Users\mquilter\Desktop\Working\T4210892

. and %e adds a dot and then the original file extension, completing the file path.

Important: This command assumes you are passing the full file path to exiftool, and you didn't CD to the directory and used *.jpg or . as the directory path.
"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

mcq

This code worked for a single image pair.

exiftool -config pix4d.config -TagsFromFile P4210892.JPG -gps:all -xmp-exif:gps* -xmp-camera:gps* P4210892-GreyTemp.jpg

The code to add GPS coordinates to all of the "T" files did not run.

exiftool -config pix4d.config -TagsFromFile %-:1dWorking\T%.1f.%e -gps:all -xmp-exif:gps* -xmp-camera:gps* C:\Users\mquilter\Desktop\ThermalTest

It produced the following:

Warning: Error opening file - C:/Users/mquilter/Desktop/Working\T4210892-GreyTemp-1.jpg
Warning: Error opening file - C:/Users/mquilter/Desktop/Working\T4210892-GreyTemp.jpg
Warning: Error opening file - C:/Users/mquilter/Desktop/Working\T4210892.JPG
Warning: Error opening file - C:/Users/mquilter/Desktop/Working\T4210892.tif
Warning: Error opening file - C:/Users/mquilter/Desktop/Working\Test-odm_orthophoto.jpg
Warning: Error opening file - C:/Users/mquilter/Desktop/Working\Test-odm_orthophoto.tif
    1 directories scanned
    0 image files updated
    6 image files unchanged

I do not understand the "%-:1dWorking\T%.1f.%e" code.  I was thinking that the code needed to be run from where the "P" (raw) files are and the path statement at the end of the code needed to be where the "T" files are so I ran the following"

C:\Users\mquilter\Desktop\ThermalTest\WorkingCopies-GIMP>exiftool -config pix4d.config -TagsFromFile %-:1dWorking\T%.1f.%e -gps:all -xmp-exif:gps* -xmp-camera:gps* C:\Users\mquilter\Desktop\ThermalTest\temp-jpeg

This went through all of the files in the directory where the "T" images are with the following error for each file.

Warning: Error opening file - C:/Users/mquilter/Desktop/ThermalTest/Working\T4210892.jpg
Warning: Error opening file - C:/Users/mquilter/Desktop/ThermalTest/Working\T4220893.jpg
Warning: Error opening file - C:/Users/mquilter/Desktop/ThermalTest/Working\T4230894.jpg
Warning: Err....................

I am sorry I don't understand your explanation - I struggle with programing.

Just to be clear as to what I am attempting is is to copy the GPS coords from raw images in one folder and add the GPS coords to corrected images in a second folder.  The images are the same and have the same name except for the first character.  The raw images start with "P" and the images with the corrected thermal data start with "T".



StarGeek

Quote from: mcq on May 02, 2025, 02:31:13 PMThe code to add GPS coordinates to all of the "T" files did not run.

Dang, I really confused myself here. Part of that is a copy/paste error (I didn't notice the space in the path) and misreading the directory paths. And also using T where the source files are P..

QuoteI do not understand the "%-:1dWorking\T%.1f.%e" code.

It complicated, but I don't think I can break it down any further than I did. I did forget to link to the -w (-TextOut) option, which is the part of the docs that explains the percent codes.

QuoteI was thinking that the code needed to be run from where the "P" (raw) files are and the path statement at the end of the code needed to be where the "T" files are so I ran the following"

As long as you include full path, it doesn't matter where you run the command.

But if you wanted to use the current directory or used a wildcard e.g. *.jpg, you would need to be in the target directory, the directory that contains the files to be changed. Not the source directory.

A bit of further thought and I changed the command in a way that would work if you CDed into the directory that contained the edited files.

exiftool -config pix4d.config -TagsFromFile "%d..\Working Copies-GIMP\T%.1f.%e" -gps:all -xmp-exif:gps* -xmp-camera:gps* C:\Users\mquilter\Desktop\ThermalTest\Temp-Jpeg

The resulting path of the %d/%f/%e format would be
C:\Users\mquilter\Desktop\ThermalTest\Temp-Jpeg\..\Working Copies-GIMP

The .. is the command line's way of moving up a step in the directory path. So you start with
C:\Users\mquilter\Desktop\ThermalTest\Temp-Jpeg\
The .. makes it
C:\Users\mquilter\Desktop\ThermalTest\
And then you add the new directory
C:\Users\mquilter\Desktop\ThermalTest\Working Copies-GIMP\
If you have changed the directory name from Working Copies-GIMP to WorkingCopies-GIMP as shown in your example, then it needs to be changed in the command.

But another problem has shown up. I didn't even notice it at the time. The XMP-Camera data in the original file is all screwed up. The part that defines the XMP-Camera data in your files shows this
xmlns:Camera="https://support.pix4d.com/hc/en-us/articles/205732309-EXIF-and-XMP-tag-information-read-by-Pix4D-Desktop"when it should be showing this (I'm not sure if the quote type matters or not)
xmlns:Camera='http://pix4d.com/camera/1.0/'
The final result means that you end up with a XMP-tmp0 tag group. I'm not sure offhand how to fix that.

Example commands
C:\>tree /f Y:\!temp\x\y\ThermalTest
Folder PATH listing for volume DrivePool
Volume serial number is 3881-4F27
Y:\!TEMP\X\Y\THERMALTEST
├───Temp-Jpeg
│       T4210892.JPG
│       
└───Working Copies-GIMP
        P4210892.JPG
       

C:\>exiftool -config pix4d.config -TagsFromFile "%d..\Working Copies-GIMP\P%.1f.%e" -gps:all -xmp-exif:gps* -xmp-camera:gps* Y:\!temp\x\y\ThermalTest\Temp-Jpeg
Warning: [minor] Entries in IFD0 were out of sequence. Fixed. - Y:/!temp/x/y/ThermalTest/Temp-Jpeg/T4210892.JPG
    1 directories scanned
    1 image files updated

C:\>exiftool -e -G1 -a -s -gps* Y:\!temp\x\y\ThermalTest\Temp-Jpeg\T4210892.JPG
[GPS]           GPSVersionID                    : 2.3.0.0
[GPS]           GPSLatitudeRef                  : North
[GPS]           GPSLatitude                     : 40 deg 23' 41.48"
[GPS]           GPSLongitudeRef                 : West
[GPS]           GPSLongitude                    : 111 deg 49' 59.18"
[GPS]           GPSAltitudeRef                  : Above Sea Level
[GPS]           GPSAltitude                     : 1404.853403 m
[GPS]           GPSSatellites                   : 26
[XMP-Camera]    GPSXYAccuracy                   : 0.736613895331249
[XMP-Camera]    GPSZAccuracy                    : 1.10000002384183
[XMP-exif]      GPSAltitude                     : 1404.85340314136 m
[XMP-exif]      GPSAltitudeRef                  : Above Sea Level
[XMP-exif]      GPSLatitude                     : 40 deg 23' 41.48" N
[XMP-exif]      GPSLongitude                    : 111 deg 49' 59.18" W
[XMP-tmp0]      GPSXYAccuracy                   : 0.736613898638506
[XMP-tmp0]      GPSZAccuracy                    : 1.10000002384186
"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

mcq

I made a couple of changes and it works perfectly.

C:\Users\mquilter\Desktop\ThermalTest\Temp-Jpeg>exiftool -config pix4d.config -TagsFromFile "%d..\WorkingCopies-GIMP\P%.1f.%e" -gps:all -xmp-exif:gps* -xmp-camera:gps* C:\Users\mquilter\Desktop\ThermalTest\Temp-Jpeg

Warning: XMP format error (no closing tag for exif:ExposureBiasValue) - C:/Users/mquilter/Desktop/ThermalTest/Temp-Jpeg/..\WorkingCopies-GIMP\P4390910.jpg
    1 directories scanned
   77 image files updated

Thank you so much for your help.  I do not think I need the XMP GPS.  If I do I will try your suggestions and look at the code.

StarGeek

Quote from: mcq on May 02, 2025, 05:08:11 PMThank you so much for your help.  I do not think I need the XMP GPS.  If I do I will try your suggestions and look at the code.

Yes, there's a very good chance that you won't need the XMP GPS tags, so it's probably ok to drop them from the command.
"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