Re: Using preallocated ImageStacks
Posted by
Michael Doube on
URL: http://imagej.273.s1.nabble.com/Using-preallocated-ImageStacks-tp3688198p3688199.html
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.