Skip to content

Incorrect image data and type after TIFF compression #5843

@XrioBtw

Description

@XrioBtw

When saving an image containing float data as a compressed TIFF the output image data and number type is incorrect (here the float32 becomes int32). The output is correct if I specify compression = None or if the input image data is of e.g. type uint8. If I specify compression = "something wrong" I get no error message, the compression defaults to "compression": "raw", but the output image data and type is still wrong.

import numpy as np
from PIL import Image
from tempfile import TemporaryFile

with TemporaryFile() as fp:
    Z = np.array([[np.pi, np.pi], [np.pi, np.pi]], dtype = np.float32)
    img = Image.fromarray(Z)
    img.save(fp, format = "TIFF", compression = "packbits")
    img = Image.open(fp)
    print(img.info)   # {'compression': 'packbits', 'dpi': (1, 1), 'resolution': (1, 1)}
    Z = np.asarray(img)
    print(Z)   # [[1078530011, 1078530011], [1078530011, 1078530011]]
    print(Z.dtype)   # int32

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions