Login  Register

Re: getPixels on ImageStack

Posted by frenshilo on May 26, 2008; 4:51pm
URL: http://imagej.273.s1.nabble.com/getPixels-on-ImageStack-tp3696139p3696141.html

Dear Albert, thank´s for your reply.

I tried your suggestion.
But it happens me a new doubt: how can I concatenate slices in only one byte[]? I tried arraycopy and it doesn´t work well. Any suggestion?

Frenshilo.



Albert Cardona wrote
frenshilo wrote:
> Hi everyone.
>
> I would like some help in converting an ImageStack to a byte[], as getPixels
> method does to an ImageProcessor.
>  


ImageStack has a method named "getPixels(int n)" which, if the stack is
made of ByteProcessor, will return byte[] for each slice from 1 to n.

http://rsb.info.nih.gov/ij/developer/api/ij/ImageStack.html


So all you need to write is:

ImagePlus imp = IJ.getImage();
ImageStack stack = imp.getStack();
if (null == stack) return;

// from 1 to size, reversed:
for (int i=stack.getSize(); i>0; i--) {
    myPlugIn((byte[])stack.getPixels(i));
}


> I´m processing 3D images and I want to reuse some older plug-in I developed
> to deal with 2D images.
>  


Albert

--
Albert Cardona
http://www.mcdb.ucla.edu/Research/Hartenstein/acardona