adding the meta data of another image

Started by Murph21, December 06, 2022, 10:49:14 AM

Previous topic - Next topic

Murph21

Hello,

I am working with drone images in python and needed to change the format of my images from DNG 12bit into Tiff 16bit. I basically gave the 16bit ndarray to gdal and created a new 16bit Tiff. Now I need to add/update the metadata of the original image to the new 16bit tiff to enable further processing of the drone images. But I am having problem with doing this with Exiftool. While it can read the tags of the original image, I am unable to add them one by one or as .csv to the new image as it does not recognize them.

Is there a quick way of adding the rest of the standard drone metadata that is not inlcuded in the new tiff file without having to configure the tags?

Attached are the both images and the .csv of the metadata of the original (original_12bit_metadata.csv) and the new 16bit Tiff image(new_16bit_metadata.csv)

I would appreciate any tips or clever ideas on how to do this. Thank you.


Phil Harvey

I looked at "original_12bit_metadata.csv".  First, this isn't a CSV file.  Second, I can't tell where the metadata is located so I can't help much.  What is the output of this command on the original DNG?:

exiftool -G1 FILE

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

Murph21

Hello Phil,

you are right I manually deleted the directory path. The unchanged file is now attached to this post as well using the following code to create it:

import subprocess
if os.environ.get('exiftoolpath') is not None:
    exiftool_cmd = os.path.normpath(os.environ.get('exiftoolpath'))
else:
    exiftool_cmd = 'exiftool'


#i_img is the path to the original 12bit DNG
cmd = '{} -r -w .csv {} '.format(exiftool_cmd, i_img)
print(cmd)
subprocess.check_call(cmd)



When I run the code you wrote I get the metadata back seen in the image "code results" 1 and 2.

Phil Harvey

I don't know what the difference is between code_results1 and 2, but I think this command may do what you need (copy the XMP as a block and the GPS from the original DNG to the TIFF):

exiftool -tagsfromfile ORIGINAL.DNG -xmp -gps:all NEW.TIF

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

Murph21

Fantastic, that single line of code transferred most of metadata. Thank you Phil :)

For further processing of images some of the others tags such as Composite:Aperture (seen in "code results 2" ) or  "Composite:ShutterSpeed" (seen in "code results2") or from "IFDO:Black Level Repeat Dim" (seen in "code results 1") are still needed.

I tried:
exiftool -tagsfromfile ORIGINAL.DNG -xmp -gps:all -composite NEW.TIF
to see if it can add composite, but I guess my syntax is wrong as nothing new was added. Is there a way to import some of the other tags from other categories (other than xmp and gps) as well?

p.s. code results 1&2 are screen shots of the metadata of the image. As they were too long I needed 2 screen shots to cover the whole metadata.


Phil Harvey

Most of the Composite tags aren't writable.  You need to copy the tags they are derived from.  See the Composite tags documentation for details.

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

Murph21

#6
Thank you so much for the tip. I was able to make it work using your code, completed with the tip! :)

exiftool -tagsfromfile SOURCE_IMAGE -xmp -gps:all -a -EXIF:all TARGE_IMAGE

Phil Harvey

Yes, that should work but copying all EXIF tags may be more than you need.  Also, the -a option has no effect when writing other than enabling the display of multiple warning messages (which I hope you're not getting).

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

Murph21

Hello again,

thank you for point it that out. Thankfully no errors so far.

Sorry for asking basic question, I am quite new to this.

There is just 1 more tag needed in the new file which is EXIF:BlackLevel. I followed this thread dealing with quite similar situation (https://exiftool.org/forum/index.php?topic=11767.15) and from what I can understand it is possible.

Would I need to create this tag in the Micasense config file and use that for -EXIF:all to transfer it, or is there possibly an easier way (without config) to transfer Blacklevel from original to new file? or create it in the new file and add the values manually?

thank you in advance,
-Mina




StarGeek

Using EXIF:All should copy the EXIF:BlackLevel, as that is writable by exiftool (see the EXIF Tags page).  That config file mentioned there was for copying the XMP-Camera/XMP-DLS tags, not EXIF tags.

EXIF:BlackLevel does require that the EXIF SubIFD group exists, but if that's in the original file it should get copied.  Unfortunately, I can't find a file I can test this out with. If using -EXIF:All doesn't copy it, then this may have to wait until Phil gets back.
* 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).

Murph21

thank you for getting back to me.

I used -EXIF:All to copy metadata and as you suspected EXIF:BlackLevel was not copied.
Attached you can  find the original 12bit DNG image (IMG_0000_4) and the target 16bit Tiff image I have copied metadata to (IMG_0000_4_16bit).

The tags that could not be copied are below. Some that are related to DNG, I do not need and I guess due to format difference are not copied. Others like "BlackLevel" is necessary to have for processing and some like 'EXIF:BlackLevelRepeatDim','EXIF:ColorMatrix1', 'EXIF:AsShotNeutral' would be nice to have, since they might be useful later.

{'EXIF:AsShotNeutral',
 'EXIF:BlackLevel',
 'EXIF:BlackLevelRepeatDim',
 'EXIF:ColorMatrix1',
 'EXIF:DNGBackwardVersion',
 'EXIF:DNGVersion',
 'EXIF:FillOrder',
 'EXIF:OpcodeList3',
 'EXIF:SubfileType'}

Any idea to test, in order to complete the metadata with necessary tags are most appreciated.

thank you
-Mina

Phil Harvey

BlackLevel is an "unsafe" tag because it may affect the image display, so it isn't copied when "all" is specified.  You need to specify it explicitly.

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

Murph21

#12
I used the below code to specify it explicitly but it did not update the image on Blacklevel.
c:\exiftool>exiftool -tagsfromfile "D:\Non-BKU\Projekte\DigiFe\data_with_NIR\3_Bilddaten_Post_PPK\3_Bilddaten_Post_PPK\S_20200730_5502_2405_2490_NIR\IMG_0000_4.tif"  -EXIF:BlackLevel "D:\Users\BKU\MinaMontakhabVijouei\Desktop\transformed_16bit_imags\IMG_0000_4_16bit.tiff"
    0 image files updated
    1 image files unchanged

although it worked for others tags like
{'EXIF:AsShotNeutral',
 'EXIF:ColorMatrix1',
 'EXIF:FillOrder'}

I also tried the code from this thread (https://exiftool.org/forum/index.php?topic=5715.0) about Blacklevel  as below and could not get it to work either (probably due to my lack of skill in coding with Exiftool)

c:\exiftool>exiftool -EXIF:BlackLevel=4800 -v2 "D:\Users\BKU\MinaMontakhabVijouei\Desktop\transformed_16bit_imags\IMG_0000_4_16bit.tiff"
Writing SubIFD:BlackLevel
======== D:/Users/BKU/MinaMontakhabVijouei/Desktop/transformed_16bit_imags/IMG_0000_4_16bit.tiff
Rewriting D:/Users/BKU/MinaMontakhabVijouei/Desktop/transformed_16bit_imags/IMG_0000_4_16bit.tiff...
  Editing tags in: IFD0 SubIFD TIFF
  Creating tags in: IFD0 SubIFD TIFF
  FileType = TIFF
  FileTypeExtension = TIF
  MIMEType = image/tiff
  Rewriting IFD0
  Rewriting XMP
  Rewriting ExifIFD
  Rewriting GPS
  Copying 320 image data blocks
Nothing changed in D:/Users/BKU/MinaMontakhabVijouei/Desktop/transformed_16bit_imags/IMG_0000_4_16bit.tiff
    0 image files updated
    1 image files unchang


I am also unable to change the values of Blacklevel in a copy of my original image, just testing access to the tag.

Is there a specific line of code that could solve this, since I am not sure what else I can try.

P.S. copy of the images are in the previous post.


Phil Harvey

The default location for BlackLevel is the SubIFD because this is a DNG tag (see the EXIF tags documentation).  This is not a normal tag for a TIFF.  Where is the tag in your source image?  ie)

exiftool -G1 -blacklevel D:\Non-BKU\Projekte\DigiFe\data_with_NIR\3_Bilddaten_Post_PPK\3_Bilddaten_Post_PPK\S_20200730_5502_2405_2490_NIR\IMG_0000_4.tif

To copy this tag, use the specific location given by the above command (eg, I'm guessing -ifd0:blacklevel).

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

Murph21


Murph21

Hello again,

I came across another problem. Namely how to change the values of XMP-MicaSense:DarkRowValues after copying into destination image. This might be unusual but since I am transforming my image from 12bit to 16bit I like to update the DarkRowValues also into 16bit range.

I tried following code to find the tags specific address:
c:\exiftool>exiftool -G1 -darkrowvalue "D:\Users\BKU\MinaMontakhabVijouei\Desktop\transformed_16bit_imags\IMG_0000_1.tif"
[XMP-MicaSense] Dark Row Value                  : 304, 304, 305, 306

and the following codes to update the value (to an arbitrary number for testing), which gives error of not recognizing the tag:
c:\exiftool>exiftool  -XMP-MicaSense:DarkRowValue="1,1,1,1" "D:\Users\BKU\MinaMontakhabVijouei\Desktop\transformed_16bit_imags\IMG_0000_1.tif"
Warning: Tag 'XMP-MicaSense:DarkRowValue' is not defined
Nothing to do.

c:\exiftool>exiftool  -XMP-MicaSense:DarkRowValue=[1,1,1,1] "D:\Users\BKU\MinaMontakhabVijouei\Desktop\transformed_16bit_imags\IMG_0000_1.tif"
Warning: Tag 'XMP-MicaSense:DarkRowValue' is not defined
Nothing to do.

c:\exiftool>exiftool  -XMP:DarkRowValue=[1,1,1,1] "D:\Users\BKU\MinaMontakhabVijouei\Desktop\transformed_16bit_imags\IMG_0000_1.tif"
Warning: Tag 'XMP:DarkRowValue' is not defined
Nothing to do.

c:\exiftool>exiftool  -DarkRowValue=[1,1,1,1] "D:\Users\BKU\MinaMontakhabVijouei\Desktop\transformed_16bit_imags\IMG_0000_1.tif"
Warning: Tag 'DarkRowValue' is not defined
Nothing to do.

Is it possible to change the darkrowvalues at all? or is there another way to change it?

Thank you very much in advance!

-Mina

Phil Harvey

Hi Mina,

The MicaSense XMP tags are not defined by ExifTool.  You will have to add user-defined tags to be able to write these.  See the sample config file for examples of how to create user-defined XMP tags.  Specifically, see NewXMPxxxTag1, but you probably want "Writable" to be a simple "string".

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