Login  Register

Using preallocated ImageStacks

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

Using preallocated ImageStacks

Adam Waite
Hello,

I am trying to write a method that takes a list of images and converts them to a stack.  Since I know the size of the list, I would like to use the ImageStack constructor that allows for preallocation.  I might be missing something very simple, but I cannot figure out the correct series of calls to assign each ImageProcessor from my list of images to the preallocated ImageStack.  The closest I can get is

// list = my list of ImagePlus objects
ImageStack stack = new ImageStack(xdim,ydim,list.size())

for (int i=0; i<list.size(); i++) {
     ImageProcessor ip =   stack.getProcessor(i+1);
     ip = list.get(i).getProcessor().duplicate();
}

This compiles, but if I try to run it, I get the following error:

Exception in thread "Run$_main" java.lang.IllegalArgumentException: Pixel array is null

Any help?  It should be more efficient to preallocate the ImageStack if possible, but perhaps this is not true.  If not, then using addSlice() is easy enough.

Thanks,
Adam



=====
Science is more of an art than a science.
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Using preallocated ImageStacks

Michael Doube
Adam,

I think this is because when you call getProcessor() the pixel array in
that slice of the stack has not been initialised.
You could try using this instead:

  ImageStack stack = new ImageStack(xdim,ydim,list.size())

  for (int i=0; i<list.size(); i++) {
        ImageProcessor ip = list.get(i).getProcessor();
        stack.setPixels(ip.getPixels, i+1);
}

I always tie myself in knots doing this simple stuff.

Michael

On 23/05/10 08:14, Adam wrote:

> Hello,
>
> I am trying to write a method that takes a list of images and converts them to a stack.  Since I know the size of the list, I would like to use the ImageStack constructor that allows for preallocation.  I might be missing something very simple, but I cannot figure out the correct series of calls to assign each ImageProcessor from my list of images to the preallocated ImageStack.  The closest I can get is
>
> // list = my list of ImagePlus objects
> ImageStack stack = new ImageStack(xdim,ydim,list.size())
>
> for (int i=0; i<list.size(); i++) {
>       ImageProcessor ip =   stack.getProcessor(i+1);
>       ip = list.get(i).getProcessor().duplicate();
> }
>
> This compiles, but if I try to run it, I get the following error:
>
> Exception in thread "Run$_main" java.lang.IllegalArgumentException: Pixel array is null
>
> Any help?  It should be more efficient to preallocate the ImageStack if possible, but perhaps this is not true.  If not, then using addSlice() is easy enough.
>
> Thanks,
> Adam
>
>
>
> =====
> Science is more of an art than a science.
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Using preallocated ImageStacks

Adam Waite
Thank you, Michael, that did the trick!

Yes, this simple task has had me banging my head against the wall for a couple days, now.

Adam

 =====
Science is more of an art than a science.



----- Original Message ----
> From: Michael Doube <[hidden email]>
> To: [hidden email]
> Sent: Sun, May 23, 2010 12:40:45 PM
> Subject: Re: Using preallocated ImageStacks
>
> Adam,

I think this is because when you call getProcessor() the pixel
> array in
that slice of the stack has not been initialised.
You could try
> using this instead:

  ImageStack stack = new
> ImageStack(xdim,ydim,list.size())

  for (int i=0; i<list.size();
> i++) {
        ImageProcessor ip =
> list.get(i).getProcessor();
    stack.setPixels(ip.getPixels,
> i+1);
}

I always tie myself in knots doing this simple
> stuff.

Michael

On 23/05/10 08:14, Adam wrote:

>
> Hello,
>
> I am trying to write a method that takes a list of images
> and converts them to a stack.  Since I know the size of the list, I would
> like to use the ImageStack constructor that allows for preallocation.  I
> might be missing something very simple, but I cannot figure out the correct
> series of calls to assign each ImageProcessor from my list of images to the
> preallocated ImageStack.  The closest I can get is
>
> // list
> = my list of ImagePlus objects
> ImageStack stack = new
> ImageStack(xdim,ydim,list.size())
>
> for (int i=0;
> i<list.size(); i++) {
>       ImageProcessor ip =  
> stack.getProcessor(i+1);
>       ip =
> list.get(i).getProcessor().duplicate();
> }
>
> This compiles,
> but if I try to run it, I get the following error:
>
> Exception in
> thread "Run$_main" java.lang.IllegalArgumentException: Pixel array is
> null
>
> Any help?  It should be more efficient to preallocate
> the ImageStack if possible, but perhaps this is not true.  If not, then
> using addSlice() is easy enough.
>
> Thanks,
>
> Adam
>
>
>
> =====
> Science is more of an art
> than a science.