Login  Register

Re: How do I get an Image stack?

Posted by Ben.BigHair on Feb 05, 2007; 2:53pm
URL: http://imagej.273.s1.nabble.com/How-do-I-get-an-Image-stack-tp3700381p3700382.html

Ilan wrote:

> To my utter surprise and delight, I managed to use ImageJ inside my
> application and it worked!
> Not that I doubt ImageJ, only my ability to use it was in strong doubt.
>
> What I did was use ij.io.Opener.open(fileName). I have a whole list of files
> and I gave it the first file on the list.
> To my delight, up came a window with my file.
> Since this works, I need to know how I can create a stack in this window and
> push in all the files.
>
> Any suggestions as where to start would be greatly appreciated.
>

Hello,

Here's a snippet from some "dusty" code that works for me...

//BEGIN
// list is the string array of filenames
Opener opener = new Opener();
ImagePlus[] imp = new ImagePlus[list.length];
ImageStack stack = new ImageStack(width, height);

try {
         for(int i = 0; i < list.length ; i++){
             imp[i] =opener.openImage(directory, list[i]);
             stack.addSlice(list[i], imp[i].getProcessor());
         }//i loop adding each image to the stack
     } catch (OutOfMemoryError e) {
         IJ.outOfMemory("Opening stack used too much memory");
     }//end of try catch
//END


Ben