Opening a single image from a tiff stack

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Opening a single image from a tiff stack

Mike Downey
Hi,

I am trying to write a plugin which needs to read in single frames from
a TIFF stack. It appears that a virtual stack is the way to go so I tried:

TiffDecoder td = new TiffDecoder(directory, filename);
FileInfo[] fi = td.getTiffInfo();
FileInfoVirtualStack vs = new FileInfoVirtualStack(fi[0]);
ImageProcessor ip = vs.getProcessor(frame);

This works but has the unwanted side effect of displaying the stack too.
I had a look at the source code and the open() method in
FileInfoVirtualStack ends with imp2.show();
Is there another way of obtaining single images from a stack (without
having to load in the entire stack or display anything unwanted on
screen)? In the meantime I have subclassed FileInfoVirtualStack and
replaced the open() method with an identical copy, apart from the
unwanted imp2.show(); command.

Thanks,
Mike.
Reply | Threaded
Open this post in threaded view
|

Re: Opening a single image from a tiff stack

Rasband, Wayne (NIH/NIMH) [E]
On Jan 21, 2011, at 8:51 AM, Mike Downey wrote:

> Hi,
>
> I am trying to write a plugin which needs to read in single frames from
> a TIFF stack. It appears that a virtual stack is the way to go so I tried:
>
> TiffDecoder td = new TiffDecoder(directory, filename);
> FileInfo[] fi = td.getTiffInfo();
> FileInfoVirtualStack vs = new FileInfoVirtualStack(fi[0]);
> ImageProcessor ip = vs.getProcessor(frame);
>
> This works but has the unwanted side effect of displaying the stack too.
> I had a look at the source code and the open() method in
> FileInfoVirtualStack ends with imp2.show();
> Is there another way of obtaining single images from a stack (without
> having to load in the entire stack or display anything unwanted on
> screen)? In the meantime I have subclassed FileInfoVirtualStack and
> replaced the open() method with an identical copy, apart from the
> unwanted imp2.show(); command.

The FileInfoVirtualStack class in the ImageJ 1.44o4 daily build has a FileInfoVirtualStack(FileInfo, false) constructor that opens a TIFF virtual stack without displaying it. Here is a JavaScript example that opens images 10-20 of a TIFF stack.

 td = new TiffDecoder(directory, fllename);
 fi = td.getTiffInfo();
 vs = new FileInfoVirtualStack(fi[0], false);
 stack = new ImageStack(vs.getWidth(), vs.getHeight());
 for (i=10; i<=20; i++)
     stack.addSlice(vs.getSliceLabel(i), vs.getProcessor(i));
 new ImagePlus("stack(10-20)", stack).show();

-wayne
Reply | Threaded
Open this post in threaded view
|

Re: Opening a single image from a tiff stack

Mike Downey
On 21/01/2011 15:29, Rasband, Wayne (NIH/NIMH) [E] wrote:

> On Jan 21, 2011, at 8:51 AM, Mike Downey wrote:
>
>> Hi,
>>
>> I am trying to write a plugin which needs to read in single frames from
>> a TIFF stack. It appears that a virtual stack is the way to go so I tried:
>>
>> TiffDecoder td = new TiffDecoder(directory, filename);
>> FileInfo[] fi = td.getTiffInfo();
>> FileInfoVirtualStack vs = new FileInfoVirtualStack(fi[0]);
>> ImageProcessor ip = vs.getProcessor(frame);
>>
>> This works but has the unwanted side effect of displaying the stack too.
>> I had a look at the source code and the open() method in
>> FileInfoVirtualStack ends with imp2.show();
>> Is there another way of obtaining single images from a stack (without
>> having to load in the entire stack or display anything unwanted on
>> screen)? In the meantime I have subclassed FileInfoVirtualStack and
>> replaced the open() method with an identical copy, apart from the
>> unwanted imp2.show(); command.
> The FileInfoVirtualStack class in the ImageJ 1.44o4 daily build has a FileInfoVirtualStack(FileInfo, false) constructor that opens a TIFF virtual stack without displaying it. Here is a JavaScript example that opens images 10-20 of a TIFF stack.
>
>   td = new TiffDecoder(directory, fllename);
>   fi = td.getTiffInfo();
>   vs = new FileInfoVirtualStack(fi[0], false);
>   stack = new ImageStack(vs.getWidth(), vs.getHeight());
>   for (i=10; i<=20; i++)
>       stack.addSlice(vs.getSliceLabel(i), vs.getProcessor(i));
>   new ImagePlus("stack(10-20)", stack).show();
>
> -wayne
Cheers Wayne, I'll give that a try.

Mike.