7

I would like to save an image as a double precision TIFF image. I have looked and tried many things but no luck. I have been able to import a double precision TIFF from IDL and found that the data was double precision. So the problem is on the export side.

data = RandomVariate[NormalDistribution[], {4, 4}]
pic = Image[data, "Real"]
ImageData[pic]
Export["Real_tiff.tiff", pic]
Import["Real_tiff.tiff", "Data"]

If you run this code you will find that the data is non-integer until it is read back in.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
c186282
  • 1,402
  • 9
  • 17

1 Answers1

11

The answer can be found in the documentation to "TIFF" when you open the IMPORT AND EXPORT subsection

When exporting an image of type "Bit16", "Real32", and "Real", Export creates a 16-bit TIFF file by default. "Byte" and "Bit" images are exported to 8-bit TIFF files.

Another thing to notice is, that Mathematica will not export negative pixel values into the created tif. As long as you have the image inside your notebook, the underlying data is not touched and negative values (or values bigger than the max of the ImageType) are displayed as black (or white) but kept in the matrix. As soon as you export the image, your pixel data gets truncated.

The (as a noticed a few seconds ago) easy solution is to set the "BitDepth" during export:

data = RandomVariate[NormalDistribution[], {4, 4}]
pic = Image[data, "Real"];

(*
-0.195911   1.98969 -0.216899   0.013856
0.0702782   0.205389    0.228991    0.773919
1.21001 1.97836 -0.814343   -1.63581
-0.981504   0.7625  0.048188    -0.64592
*)

And now

Export["Real_tiff.tiff", pic, "BitDepth" -> 64];
Import["Real_tiff.tiff", "Data"]

(*
-0.195911   1.98969 -0.216899   0.013856
0.0702782   0.205389    0.228991    0.773919
1.21001 1.97836 -0.814343   -1.63581
-0.981504   0.7625  0.048188    -0.64592
*)
halirutan
  • 112,764
  • 7
  • 263
  • 474