-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Incorrect image data and type after TIFF compression #5843
Copy link
Copy link
Closed
Labels
Description
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) # int32Reactions are currently unavailable