8
$\begingroup$

After trying to import a $\approx 2$ GB TIF file with the Import command, I noticed that the process takes $\approx 15$ minutes or so, which seems excessive, especially when compared to other software packages. Attempting to load TIF files $>10$ GB in size can take over an hour. Surely there must be some trick to accelerate the import procedure? If not, can anyone explain to me why this is occurring? Perhaps it is generating an index of the individual images in some inefficient manner?

I have a 64-bit system and I'm happy to use an arbitrary amount of memory - speed is what matters to me.

$\endgroup$
14
  • $\begingroup$ What amount of physical memory does your computer have? $\endgroup$ Jun 30, 2013 at 18:43
  • $\begingroup$ @SjoerdC.deVries 128 GB of RAM. $\endgroup$
    – SparsePine
    Jun 30, 2013 at 18:45
  • $\begingroup$ Ohhhkay... What are the dimensions of the image? $\endgroup$ Jun 30, 2013 at 20:06
  • $\begingroup$ @SjoerdC.deVries It's a stack of 256 x 256 pixel images with real numbered pixel values? $\endgroup$
    – SparsePine
    Jun 30, 2013 at 20:07
  • 1
    $\begingroup$ (I suspect that you want a purely Mathematica function but) Have you tried to import with libtiff via MathLink? If you do a lot of reading, maybe it's worth investigating it. $\endgroup$
    – Eric Brown
    Jun 30, 2013 at 21:15

2 Answers 2

4
$\begingroup$

I'm not sure it will help in your case (it depends on exactly what your files contain), but you can sometimes import just pieces/elements of a file instead of the whole thing. For example, you can check what kind of information a file contains using

Import["ExampleData/rose.gif", "Elements"]

{"Animation", "AnimationRepetitions", "Background", "BitDepth",
 "ColorMap", "ColorSpace", "Comments", "Data", "DataType",
 "DisplayDurations", "Frames", "GlobalColorMap", "Graphics",
 "GraphicsList", "GrayLevels", "Image", "ImageCount", "ImageList",
 "ImageSize", "RawData", "RGBColorArray", "TransitionEffect", "UserInputFlag"}

and then choose to import only those parts that you need to work with, for example:

Import["ExampleData/rose.gif", "GrayLevels"]
$\endgroup$
4
$\begingroup$

I cannot confirm your timings.

 AbsoluteTiming[
   data = ConstantArray[
    Image[ConstantArray[4095, {1024, 1024}], "Bit16"], 768]; 
 Export["C:\\Users\\stelzer\\Desktop\\test.tif", data, "TIFF"];
(* {6.765371, Null} *)

FileByteCount["C:\\Users\\stelzer\\Desktop\\test.tif"]
(* 1611793936 *)

AbsoluteTiming[
 dataIn = Import["C:\\Users\\stelzer\\Desktop\\test.tif", "TIFF"];]
(* {10.086806, Null} *)

Length /@ {data, dataIn}
(* {768, 768} *)
$\endgroup$
1
  • $\begingroup$ Seems to scale worse with the number of frames: Export["~/test.tif", Table[Image[Table[RandomReal[], {i, 1, 256}, {j, 1, 256}]], {k, 1, 5000}], "TIFF"]; First@AbsoluteTiming[Import["~/test.tif", "TIFF"];] is about 3 minutes on my system (which is pretty old.) $\endgroup$ Jul 2, 2013 at 11:29

Your Answer

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

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