LeoHsiao1 / pyexiv2

Read and write image metadata, including EXIF, IPTC, XMP, ICC Profile.
GNU General Public License v3.0
202 stars 39 forks source link

tif 图获取ICC Profile解码出错 #112

Closed sanbuphy closed 1 year ago

sanbuphy commented 1 year ago

你好,我在尝试用pyexiv2对一个tif图片进行解码,我想把它的icc profile读取后应用在其他的rgb图像上。但是现在我遇到了一个问题,就是我发现读取后会显示一大段的字节串:

b'\x00\x08\x80pADBE\x02\x10\x00\x00prtrCMYKLab \x07\xd2\x00\t\x00\x01\x00\x00\x00\x00\x00\x01acspAPPL\x00\x00\x00\x00ADBE\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf6\xd6\x00\x01\x00\x00\x00\x00\xd3-ADBE\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\ndesc\x00\x00\x00\xfc\x00\x00\x00rcprt\x00\x00\x01p\x00\x00\x00+wtpt\x00\x00\x01\x9c\x00\x00\x00\x14A2B0\x00\x00\x01\xb0\x00\x00\xa2\x06A2B2\x00\x00\x01\xb0\x00\x00\xa2\x06A2B1\x00\x00\xa3\xb8'

如果尝试decode变成utf-8的话,会直接报错,请问我该如何解决这个问题?感谢。

LeoHsiao1 commented 1 year ago

icc 本来就是二进制数据,不是字符串文本,所以不需要 decode 或者 encode ,保存为 python bytes 对象即可。 https://en.wikipedia.org/wiki/ICC_profile

sanbuphy commented 1 year ago

icc 本来就是二进制数据,不是字符串文本,所以不需要 decode 或者 encode ,保存为 python bytes 对象即可。 https://en.wikipedia.org/wiki/ICC_profile

谢谢您的回复,那我该如何把他作用在另外一个RGB图像上呢,主要是想对颜色配置信息做解析处理

LeoHsiao1 commented 1 year ago

示例代码:

data = img1.read_icc()
img2.modify_icc(data)

并没有特别的地方

sanbuphy commented 1 year ago

示例代码:

data = img1.read_icc()
img2.modify_icc(data)

并没有特别的地方

应用后,请问有什么api可以保存这个应用后的图片吗

LeoHsiao1 commented 1 year ago

请看教程: https://github.com/LeoHsiao1/pyexiv2/blob/master/docs/Tutorial-cn.md#class-image

sanbuphy commented 1 year ago

请看教程: https://github.com/LeoHsiao1/pyexiv2/blob/master/docs/Tutorial-cn.md#class-image

好的,感谢,我看了,不过这样操作后最后图片的颜色并没有变化(确定读取到了icc的数据格式) 还是感谢大佬

    with pyexiv2.Image(r'2ZTMC8Q6J5DS.tif') as image:
        icc_profile = image.read_icc()
    with pyexiv2.Image(r'rgb_image.png') as image2:
        image2.modify_icc(icc_profile)