Question

I am trying to update certain tiff tag value using the GDAL python binding.

for example, using tiffinfo I can read the tags value from the image, it is something like this:

TIFF Directory at offset 0x8 (8) Image Width: 4172 Image Length: 3689 Tile Width: 256 Tile Length: 256 Bits/Sample: 8 Sample Format: unsigned integer Compression Scheme: JPEG Photometric Interpretation: YCbCr Samples/Pixel: 3 Planar Configuration: single image plane Tag 33550: 60.000000,60.000000,0.000000 Tag 33922: 0.000000,0.000000,0.000000,588840.000000,4880460.000000,0.000000 Tag 34735: 1,1,0,7,1024,0,1,1,1025,0,1,1,1026,34737,22,0,2049,34737,7,22,2054,0,1,9102,3072,0,1,32618,3076,0,1,9001

I want to update "Tag 33922" with a different value without saving a new image. But I couldn't find a method to update the tag value in the GDAL python API.

Did I miss something or this is just simply not supported in GDAL python binding?

Thanks Jie

Was it helpful?

Solution

Thanks cgohlke for showing me the libtiff wrapper in python. I ended up writing C# code using the LibTiff.Net API. It looks something like this:

using (Tiff image = Tiff.Open(filePaths[i], "a"))
{        
    image.SetDirectory(0);

    // read auto-registered tag 33922
    FieldValue[] value = image.GetField((TiffTag)33922);
    int count = value[0].ToInt();
    double[] array = value[1].ToDoubleArray();
    System.Console.Out.WriteLine("Tag 33922 value(s) are as follows:");
    System.Console.Out.WriteLine(string.Join(",", array));

    double[] newarray = { 0.5, 0.5, 0, array[3], array[4], array[5] };
    image.SetField((TiffTag)33922, 6, newarray);

    System.Console.Out.WriteLine("Tag 33922 value(s) have been updated to:");
    System.Console.Out.WriteLine(string.Join(",", newarray));

    // Write the information to the file
    image.CheckpointDirectory();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top