Output work array to stack

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

Output work array to stack

Michael Doube
Hi all

I have an elementary question, which I have been unable to solve myself:
I have an array with nSlices*width*height elements, indexed like:
workArray[z*width*height+y*width+x]

What's the best way to output this to a new stack?  I've tried this:

int sliceSize=w*h;
ImageStack target = new ImageStack(w,h);
short[] sliceArray = new short[sliceSize];
for (int z = 1; z < al; z++){
   System.arraycopy(workArray, z*sliceSize, sliceArray, 0, sliceSize);
   target.addSlice("slice "+z, sliceArray);
}
ImagePlus target2 = new ImagePlus("Aligned", target);
target2.show();

But the stack output contains only last slice repeated through the whole
stack.

Thanks

Mike
Reply | Threaded
Open this post in threaded view
|

Re: Output work array to stack

Stephan Saalfeld
Hi Mike,

currelntly, all slices share the same pixels.  Change the code to

int sliceSize=w*h;
ImageStack target = new ImageStack(w,h);
for (int z = 0; z < al; z++){
   short[] sliceArray = new short[sliceSize];
   System.arraycopy(workArray, z*sliceSize, sliceArray, 0, sliceSize);
   target.addSlice("slice "+(z+1), sliceArray);
}
ImagePlus target2 = new ImagePlus("Aligned", target);
target2.show();

that should work.

Best regards,
Stephan

On Fri, 2008-08-22 at 10:59 +0100, Michael Doube wrote:

> Hi all
>
> I have an elementary question, which I have been unable to solve myself:
> I have an array with nSlices*width*height elements, indexed like:
> workArray[z*width*height+y*width+x]
>
> What's the best way to output this to a new stack?  I've tried this:
>
> int sliceSize=w*h;
> ImageStack target = new ImageStack(w,h);
> short[] sliceArray = new short[sliceSize];
> for (int z = 1; z < al; z++){
>    System.arraycopy(workArray, z*sliceSize, sliceArray, 0, sliceSize);
>    target.addSlice("slice "+z, sliceArray);
> }
> ImagePlus target2 = new ImagePlus("Aligned", target);
> target2.show();
>
> But the stack output contains only last slice repeated through the whole
> stack.
>
> Thanks
>
> Mike