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.

  • $\begingroup$ What amount of physical memory does your computer have? $\endgroup$ – Sjoerd C. de Vries Jun 30 '13 at 18:43
  • $\begingroup$ @SjoerdC.deVries 128 GB of RAM. $\endgroup$ – SparsePine Jun 30 '13 at 18:45
  • $\begingroup$ Ohhhkay... What are the dimensions of the image? $\endgroup$ – Sjoerd C. de Vries Jun 30 '13 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 '13 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 '13 at 21:15

I cannot confirm your timings.

In[49]:= AbsoluteTiming[
 data = ConstantArray[
   Image[ConstantArray[4095, {1024, 1024}], "Bit16"], 768]; 
 Export["C:\\Users\\stelzer\\Desktop\\test.tif", data, "TIFF"];]

Out[49]= {6.765371, Null}

In[50]:= FileByteCount["C:\\Users\\stelzer\\Desktop\\test.tif"]

Out[50]= 1611793936

In[51]:= AbsoluteTiming[
 dataIn = Import["C:\\Users\\stelzer\\Desktop\\test.tif", "TIFF"];]

Out[51]= {10.086806, Null}

In[52]:= Length /@ {data, dataIn}

Out[52]= {768, 768}
  • $\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$ – Corey Kelly Jul 2 '13 at 11:29

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"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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