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.

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.

share|improve this question
    
What amount of physical memory does your computer have? –  Sjoerd C. de Vries Jun 30 '13 at 18:43
    
@SjoerdC.deVries 128 GB of RAM. –  SparsePine Jun 30 '13 at 18:45
    
Ohhhkay... What are the dimensions of the image? –  Sjoerd C. de Vries Jun 30 '13 at 20:06
    
@SjoerdC.deVries It's a stack of 256 x 256 pixel images with real numbered pixel values? –  SparsePine Jun 30 '13 at 20:07
1  
(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. –  Eric Brown Jun 30 '13 at 21:15
show 9 more comments

2 Answers 2

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}
share|improve this answer
    
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.) –  Corey Kelly Jul 2 '13 at 11:29
add comment

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"]
share|improve this answer
add comment

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.