Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 10 down vote accepted

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
*)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.