7
$\begingroup$

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.

$\endgroup$

1 Answer 1

11
$\begingroup$

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
*)
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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