2

I am trying to read a multipage tiff which is 128 pixels x 128 pixels x 122000 frames. Reading the file with the following code:

InfoImage=imfinfo(fname);
mImage=InfoImage(1).Width;
nImage=InfoImage(1).Height;
NumberImages=length(InfoImage);
image=zeros(nImage,mImage,NumberImages,'uint16'); 
TifLink = Tiff(fname, 'r');
for i=1:NumberImages
   TifLink.setDirectory(i);
   image(:,:,i)=TifLink.read();
end
TifLink.close();

produces the following error:

Error using tifflib
Input argument out of range.

Error in Tiff/setDirectory (line 1277)
        tifflib('setDirectory',obj.FileID,dirNum-1);

Error in TiffReader (line 18)
   TifLink.setDirectory(i);

at exactly i = 65537, or 2^16 + 1.

It seems that MATLAB thinks that a tiff cannot possibly be longer than 65536 frames, which is clearly not the case, because I have one which opens just fine in ImageJ.

Does anyone know what the problem might be?

user3542918
  • 91
  • 1
  • 3
  • Which version of MATLAB are you using? MATLAB uses libtiff under the hood, an older version of libtiff used short int's for certain Tiff fields which might explain what you are seeing. The latest version of MATLAB uses libtiff 4.0 which ought not have this issue. (Use Tiff.getVersion). I havent had a chance to check yet. – Ashish Uthama Apr 21 '14 at 12:01
  • 1
    I have tried it with LIBTIFF Version 4.0.0 on R2013b (Linux) and R2014a (Mac). FYI you may also be interested in my other question here: [link](http://stackoverflow.com/questions/23163048/matlab-write-multipage-tiff-exponentially-slow) – user3542918 Apr 22 '14 at 14:55

1 Answers1

0

The TIFFStack library for Matlab is able to import these files. https://github.com/DylanMuir/TIFFStack