Re: Opening a single image from a tiff stack
Posted by
Rasband, Wayne (NIH/NIMH) [E] on
Jan 21, 2011; 3:29pm
URL: http://imagej.273.s1.nabble.com/Opening-a-single-image-from-a-tiff-stack-tp3685932p3685933.html
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