Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save 32-bit floating point TIFF image

I'm trying to save a 32-bit floating point image (stored as a Numpy array) as a TIFF file using tifffile.py.

import numpy as np
import tifffile

image = np.random.rand(500, 500, 3).astype(np.float32)
tifffile.imsave('image.tiff', image)

However, when viewing the output of the above code in Eye of Gnome, the image is entirely blank.

Screenshot

like image 904
Omegastick Avatar asked Sep 08 '25 10:09

Omegastick


1 Answers

I think the problem is that not all tools support multi-channel TIFFs with 32-bits per channel. For example, as far as I can tell Python's PIL library does not. But I think tifffile.py does, because if I use your code I get a TIFF that opens, and looks reasonable, in GIMP:

GIMP with the image

From what I read, Photoshop can read 32-bit TIFFs too. So I think the TIFF file contains your image, but whether it works for you or not depends on what you want to do with it next.

This question might be relevant too, although it's about using 16-bit integers not floats: Python: Read and write TIFF 16 bit , three channel , colour images

like image 78
Matt Hall Avatar answered Sep 10 '25 00:09

Matt Hall