1

我正在尝试使用 GDAL python 绑定更新某些 tiff 标签值。

例如,使用 tiffinfo 我可以从图像中读取标签值,它是这样的:

偏移量 0x8 (8) 处的 TIFF 目录 图像宽度:4172 图像长度:3689 瓦片宽度:256 瓦片长度:256 位/样本:8 样本格式:无符号整数 压缩方案:JPEG 光度解释:YCbCr 样本/像素:3 平面配置:单幅图像平面标签33550:60.000000,60.000000,0.000000标签33922:0.000000,0.000000,0.000000,58880.000000,4880460.000000,0.0000,0.000000.000000,0.000000标签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

我想用不同的值更新“标签 33922”而不保存新图像。但我找不到在 GDAL python API 中更新标签值的方法。

我错过了什么,或者这在 GDAL python 绑定中根本不支持?

谢谢杰

4

1 回答 1

0

感谢 cgohlke 向我展示了 python 中的 libtiff 包装器。我最终使用 LibTiff.Net API 编写了 C# 代码。它看起来像这样:

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();
}
于 2012-04-24T06:10:14.900 回答