Thread Subject: Problem reading multi-image TIFF files

Subject: Problem reading multi-image TIFF files

From: Francis Burton

Date: 9 Nov, 2009 08:43:57

Message: 1 of 11

I'm trying to read some image stacks in TIFF format using
imread. The files are created by commercial deconvolution
software. I get the following error:

im=imread('1.stk','Index',3);
??? Error using ==> rtifc
Invalid TIFF image index specified.

Error in ==> readtif at 52
[X, map, details] = rtifc(args);

Error in ==> imread at 430
    [X, map] = feval(fmt_s.read, filename, extraArgs{:});

However, the file opens fine with ImageJ, and if I save
it back to another file, the new file can then be read by
MATLAB.

Does this indicate that the original image stack file is
non-conformant to the TIFF standard, or could it be a
problem with MATLAB itself?

(At the moment, I am working round the problem by invoking
ImageJ in command line mode and getting it to run a macro
to 'convert' each image stack that needs to be read. This
is very slow and a horrible kludge.)

Francis

Subject: Problem reading multi-image TIFF files

From: ImageAnalyst

Date: 9 Nov, 2009 11:28:38

Message: 2 of 11

On Nov 9, 3:43 am, Francis Burton <fbur...@nyx.net> wrote:
> I'm trying to read some image stacks in TIFF format using
> imread. The files are created by commercial deconvolution
> software. I get the following error:
>
> im=imread('1.stk','Index',3);
> ??? Error using ==> rtifc
> Invalid TIFF image index specified.
>
> Error in ==> readtif at 52
> [X, map, details] = rtifc(args);
>
> Error in ==> imread at 430
>     [X, map] = feval(fmt_s.read, filename, extraArgs{:});
>
> However, the file opens fine with ImageJ, and if I save
> it back to another file, the new file can then be read by
> MATLAB.
>
> Does this indicate that the original image stack file is
> non-conformant to the TIFF standard, or could it be a
> problem with MATLAB itself?
>
> (At the moment, I am working round the problem by invoking
> ImageJ in command line mode and getting it to run a macro
> to 'convert' each image stack that needs to be read. This
> is very slow and a horrible kludge.)
>
> Francis

-----------------------------------------------------------------
What version do you have? R2009b has a new Tiff reader function that
you can use instead of imread. But I bet imread will still work if
you call it correctly and have a valid image.

Subject: Problem reading multi-image TIFF files

From: fburton@nyx.net (Francis Burton)

Date: 9 Nov, 2009 12:29:06

Message: 3 of 11

In article <5aa1ff6c-4d5e-4f87-8f25-f8ea149c6ac9@m35g2000vbi.googlegroups.com>,
ImageAnalyst <imageanalyst@mailinator.com> wrote:
>-----------------------------------------------------------------
>What version do you have? R2009b has a new Tiff reader function that
>you can use instead of imread. But I bet imread will still work if
>you call it correctly and have a valid image.

R2009a sadly.

imfinfo('original.stk') gives some strange 'Software' and 'DateTime'
field values:

                     Filename: [1x59 char]
                  FileModDate: '21-Mar-2009 09:57:28'
                     FileSize: 6516203
                       Format: 'tif'
                FormatVersion: []
                        Width: 696
                       Height: 520
                     BitDepth: 16
                    ColorType: 'grayscale'
              FormatSignature: [73 73 42 0]
                    ByteOrder: 'little-endian'
               NewSubFileType: 0
                BitsPerSample: 16
                  Compression: 'Uncompressed'
    PhotometricInterpretation: 'BlackIsZero'
                 StripOffsets: [104x1 double]
              SamplesPerPixel: 1
                 RowsPerStrip: 5
              StripByteCounts: [104x1 double]
                  XResolution: 72
                  YResolution: 72
               ResolutionUnit: 'Inch'
                     Colormap: []
          PlanarConfiguration: 'Chunky'
                    TileWidth: []
                   TileLength: []
                  TileOffsets: []
               TileByteCounts: []
                  Orientation: 1
                    FillOrder: 1
             GrayResponseUnit: 0.0100
               MaxSampleValue: 65535
               MinSampleValue: 0
                 Thresholding: 1
                       Offset: 6515981
                     Software: 'II*
mc * ^Z ^Z * '
                     DateTime: ' * ( ' % & ^Z
 ^Z '

(The ^Z's really are Ctrl-Zs - they caused trn to suspend when I
pasted in the MATLAB output!)

After the file has been through ImageJ, I get this:

>> f=imfinfo('processed.tif');
>> f(1)

ans =

                     Filename: 'processed.tif'
                  FileModDate: '08-Nov-2009 14:56:48'
                     FileSize: 6515924
                       Format: 'tif'
                FormatVersion: []
                        Width: 696
                       Height: 520
                     BitDepth: 16
                    ColorType: 'grayscale'
              FormatSignature: [77 77 42 0]
                    ByteOrder: 'little-endian'
               NewSubFileType: 0
                BitsPerSample: 16
                  Compression: 'Uncompressed'
    PhotometricInterpretation: 'BlackIsZero'
                 StripOffsets: 356
              SamplesPerPixel: 1
                 RowsPerStrip: 520
              StripByteCounts: 723840
                  XResolution: []
                  YResolution: []
               ResolutionUnit: 'None'
                     Colormap: []
          PlanarConfiguration: 'Chunky'
                    TileWidth: []
                   TileLength: []
                  TileOffsets: []
               TileByteCounts: []
                  Orientation: 1
                    FillOrder: 1
             GrayResponseUnit: 0.0100
               MaxSampleValue: 65535
               MinSampleValue: 0
                 Thresholding: 1
                       Offset: 8
             ImageDescription: [1x61 char]
                  UnknownTags: [2x1 struct]

So I guess what is happening is that ImageJ is stripping out
the corrupted fields, allowing MATLAB to read the file.

Francis

Subject: Problem reading multi-image TIFF files

From: Steve Eddins

Date: 9 Nov, 2009 12:30:09

Message: 4 of 11

Francis Burton wrote:
> I'm trying to read some image stacks in TIFF format using
> imread. The files are created by commercial deconvolution
> software. I get the following error:
>
> im=imread('1.stk','Index',3);
> ??? Error using ==> rtifc
> Invalid TIFF image index specified.
>
> Error in ==> readtif at 52
> [X, map, details] = rtifc(args);
>
> Error in ==> imread at 430
> [X, map] = feval(fmt_s.read, filename, extraArgs{:});
>
> However, the file opens fine with ImageJ, and if I save
> it back to another file, the new file can then be read by
> MATLAB.
>
> Does this indicate that the original image stack file is
> non-conformant to the TIFF standard, or could it be a
> problem with MATLAB itself?
>
> (At the moment, I am working round the problem by invoking
> ImageJ in command line mode and getting it to run a macro
> to 'convert' each image stack that needs to be read. This
> is very slow and a horrible kludge.)
>
> Francis

Can you post the output of imfinfo on the file?

---
Steve Eddins
http://blogs.mathworks.com/steve/

Subject: Problem reading multi-image TIFF files

From: fburton@nyx.net (Francis Burton)

Date: 9 Nov, 2009 13:29:05

Message: 5 of 11

In article <hd920h$mi3$1@fred.mathworks.com>,
Steve Eddins <Steve.Eddins@mathworks.com> wrote:
>
>Can you post the output of imfinfo on the file?

See my other post. (Actually, the original file was called
'1.stk' - I changed it to 'original.stk' to make the meaning
clearer - not that would make much difference, I imagine.
I also changed the little rectangular symbols, some of which
were undoubtedly Ctrl-Zs, into '^Z'.)

Grateful you're taking a look at this, Steve.

Francis

Subject: Problem reading multi-image TIFF files

From: Steve Eddins

Date: 9 Nov, 2009 13:54:08

Message: 6 of 11

Francis Burton wrote:
> In article <hd920h$mi3$1@fred.mathworks.com>,
> Steve Eddins <Steve.Eddins@mathworks.com> wrote:
>> Can you post the output of imfinfo on the file?
>
> See my other post. (Actually, the original file was called
> '1.stk' - I changed it to 'original.stk' to make the meaning
> clearer - not that would make much difference, I imagine.
> I also changed the little rectangular symbols, some of which
> were undoubtedly Ctrl-Zs, into '^Z'.)
>
> Grateful you're taking a look at this, Steve.
>
> Francis

It wasn't clear to me in your other post whether the output of imfinfo
for the original file was a single structure or a structure array.

What does this return:

numel(imfinfo('original.stdk'))

---
Steve Eddins
http://blogs.mathworks.com/steve/

Subject: Problem reading multi-image TIFF files

From: fburton@nyx.net (Francis Burton)

Date: 9 Nov, 2009 14:36:25

Message: 7 of 11

In article <hd96u0$7r4$1@fred.mathworks.com>,
Steve Eddins <Steve.Eddins@mathworks.com> wrote:
>It wasn't clear to me in your other post whether the output of imfinfo
>for the original file was a single structure or a structure array.
>
>What does this return:
>
>numel(imfinfo('original.stdk'))

Ah, good point. This is what I see:

>> f=imfinfo('1.stk');
Warning: The computation of the tag value for "" involves division
by zero. The value has been set to NaN.
>> numel(f)

ans =

     1

On the other hand:

>> f=imfinfo('1.tif'); % 1.tif is processed version of 1.tsk
>> numel(f)

ans =

     9

Also, I can do im=imread('1.stk') without any errors, but it only
lets me retrieve the first image in the stack, thus:

>> im=imread('1.stk','Index',1);
>> im=imread('1.stk','Index',2);
??? Error using ==> rtifc
Invalid TIFF image index specified.

Error in ==> readtif at 52
[X, map, details] = rtifc(args);

Error in ==> imread at 430
    [X, map] = feval(fmt_s.read, filename, extraArgs{:});

Francis

Subject: Problem reading multi-image TIFF files

From: Steve Eddins

Date: 9 Nov, 2009 16:00:12

Message: 8 of 11

Francis Burton wrote:
> In article <hd96u0$7r4$1@fred.mathworks.com>,
> Steve Eddins <Steve.Eddins@mathworks.com> wrote:
>> It wasn't clear to me in your other post whether the output of imfinfo
>> for the original file was a single structure or a structure array.
>>
>> What does this return:
>>
>> numel(imfinfo('original.stdk'))
>
> Ah, good point. This is what I see:
>
>>> f=imfinfo('1.stk');
> Warning: The computation of the tag value for "" involves division
> by zero. The value has been set to NaN.
>>> numel(f)
>
> ans =
>
> 1

Can you send me the file? If it's less than about 9 MB you can sent it
to me via e-mail.

---
Steve Eddins
http://blogs.mathworks.com/steve/

Subject: Problem reading multi-image TIFF files

From: fburton@nyx.net (Francis Burton)

Date: 9 Nov, 2009 16:33:06

Message: 9 of 11

In article <hd9eac$8f0$1@fred.mathworks.com>,
Steve Eddins <Steve.Eddins@mathworks.com> wrote:
>Can you send me the file? If it's less than about 9 MB you can sent it
>to me via e-mail.

Sure! It's a bit over 6MB. I'll send it from my other email
account. I appreciate your taking the time to look at this.

Francis

Subject: Problem reading multi-image TIFF files

From: Steve Eddins

Date: 9 Nov, 2009 17:23:59

Message: 10 of 11

Francis Burton wrote:
> In article <hd9eac$8f0$1@fred.mathworks.com>,
> Steve Eddins <Steve.Eddins@mathworks.com> wrote:
>> Can you send me the file? If it's less than about 9 MB you can sent it
>> to me via e-mail.
>
> Sure! It's a bit over 6MB. I'll send it from my other email
> account. I appreciate your taking the time to look at this.
>
> Francis

Thanks for sending me the file.

The file is a MetaMorph Stack (STK) file. The multiple images in the
file are not stored in the normal TIFF fashion. Rather, they are stored
using proprietary private tags.

Here is documentation describing how the stack images are stored:

http://support.meta.moleculardevices.com/docs/t10243.pdf
ftp://ftp.meta.moleculardevices.com/support/stack/STK.doc

I found some MATLAB code online that claims to be able to read MetaMorph
Stack files:

http://www.embl.de/~nedelec/misc/

---
Steve Eddins
http://blogs.mathworks.com/steve/

Subject: Problem reading multi-image TIFF files

From: fburton@nyx.net (Francis Burton)

Date: 9 Nov, 2009 17:50:50

Message: 11 of 11

In article <hd9j7f$q54$1@fred.mathworks.com>,
Steve Eddins <Steve.Eddins@mathworks.com> wrote:
>The file is a MetaMorph Stack (STK) file. The multiple images in the
>file are not stored in the normal TIFF fashion. Rather, they are stored
>using proprietary private tags.
>
>Here is documentation describing how the stack images are stored:
>
>http://support.meta.moleculardevices.com/docs/t10243.pdf
>ftp://ftp.meta.moleculardevices.com/support/stack/STK.doc
>
>I found some MATLAB code online that claims to be able to read MetaMorph
>Stack files:
>
>http://www.embl.de/~nedelec/misc/

Looks hopeful! I had to change

~isempty(IMG.info) to isfield(IMG, 'info')

to get rid of an error message, but it seems to allow access to
all images in the stack, which is what I needed.

Many thanks for your help. I think you saved me a lot of hassle.

Francis

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com