3

I've created multi-page tiff files with a macro in ImageJ, and I'm now trying to open it using matlab, but I can only access the first frame.

Here is the result of imfinfo(filename). Accordingly, I get

length(imfinfo(filename)) = 1

Filename: [1x129 char]
              FileModDate: '28-nov-2013 12:27:51'
                 FileSize: 6.7905e+09
                   Format: 'tif'
            FormatVersion: []
                    Width: 512
                   Height: 512
                 BitDepth: 8
                ColorType: 'grayscale'
          FormatSignature: [77 77 0 42]
                ByteOrder: 'big-endian'
           NewSubFileType: 0
            BitsPerSample: 8
              Compression: 'Uncompressed'
PhotometricInterpretation: 'BlackIsZero'
             StripOffsets: 932625
          SamplesPerPixel: 1
             RowsPerStrip: 512
          StripByteCounts: 262144
              XResolution: []
              YResolution: []
           ResolutionUnit: 'None'
                 Colormap: []
      PlanarConfiguration: 'Chunky'
                TileWidth: []
               TileLength: []
              TileOffsets: []
           TileByteCounts: []
              Orientation: 1
                FillOrder: 1
         GrayResponseUnit: 0.0100
           MaxSampleValue: 255
           MinSampleValue: 0
             Thresholding: 1
                   Offset: 8
         ImageDescription: 'ImageJ=1.47q
 images=25900
 slices=25900
 loop=false

However if I open the same tif file in ImageJ, then I can read and scroll through the 25900 frames...The weird thing is that matlab can read previous multipage tiff I had created in imageJ without my batch macro...

I don't understand what's happening...any help would be greatly appreciated ! Thanks, Steven

user3049481
  • 31
  • 1
  • 3

2 Answers2

2

This is actually ImageJ's fault. For large TIFFs, instead of using the BigTiff standard to save the stack, ImageJ instead saves a raw file with a fake TIFF header containing the first frame, and happily names it .tif. You can discuss with the ImageJ developers why they think this is a good idea.

To read these stacks into Matlab, you can use memmapfile or MappedTensor.

-1

You have to loop over all the images in the stack:

fname = 'my_file_with_lots_of_images.tif';
info = imfinfo(fname);
imageStack = [];
numberOfImages = length(info);
for k = 1:numberOfImages
    currentImage = imread(fname, k, 'Info', info);
    imageStack(:,:,k) = currentImage;
end 
Olivier
  • 921
  • 10
  • 19
  • 1
    Thanks for your comment, but I was already doing this. I've actually realized this error was due to the large size of the tiff stack: whenever it's bigger than about 5 Gb, Matlab only sees the first frame, but if I decreased the size by splitting the file, then it works... Quite annoying because I had to rewrite the script but I didn't found any other solution... – user3049481 Nov 30 '13 at 10:34
  • This process would be a lot faster if properly preallocating `imageStac`. Even the MATLAB editor will warn you about increasing the size of a matrix within a loop. – Cris Luengo Dec 16 '18 at 15:36