getPixels on ImageStack

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

getPixels on ImageStack

frenshilo
Hi everyone.

I would like some help in converting an ImageStack to a byte[], as getPixels method does to an ImageProcessor.

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

Thanx
Reply | Threaded
Open this post in threaded view
|

Re: getPixels on ImageStack

Fabrice Senger
frenshilo a écrit :

> Hi everyone.
>
> I would like some help in converting an ImageStack to a byte[], as getPixels
> method does to an ImageProcessor.
>
> I´m processing 3D images and I want to reuse some older plug-in I developed
> to deal with 2D images.
>
> Thanx
>  
you might convert your stacks to single images in a folder and then
batch process those images with your plug-ins, using the batch process
macro.

Cheers,

Fabrice.

--
Senger Fabrice
Reply | Threaded
Open this post in threaded view
|

Re: getPixels on ImageStack

Albert Cardona
In reply to this post by frenshilo
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
Reply | Threaded
Open this post in threaded view
|

Re: getPixels on ImageStack

frenshilo
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
Reply | Threaded
Open this post in threaded view
|

Re: getPixels on ImageStack

Albert Cardona
frenshilo wrote:
> 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?
>  


You need to read some basic java documentation. I suggest "Thinking in
Java", which is free and online and fairly complete.

http://www.linuxguruz.com/ebooks/eckel/
http://www.linuxguruz.org/ebooks/eckel/TIJ-3rd-edition2.0.zip

Albert

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