Login  Register

Re: How can I access to the whole stack?

Posted by Michael Schmid on Jul 07, 2009; 6:20pm
URL: http://imagej.273.s1.nabble.com/How-can-I-access-to-the-whole-stack-tp3691874p3691877.html

Hi Juanjo,

one not so intuitive point that you seem to have missed:

Stack slices are not numbered 0...(n-1) but 1...n.

So it should be
   ...getProcessor(stack+1)...

(for whatever reason you name the silces 'stack', not 'slice' - this
obfuscates the code somewhat)

Michael

_________________________________________________________

On Tue, July 7, 2009 14:30, Juanjo Vega wrote:

> Hello,
>
> I'm trying to process an entire stack, but I'm having some problems.
>
> I wrote the code below in order to understand how to access to each one
> of the stack slices. The idea is to copy the whole stack into a matrix
> where each row is a slice and columns store the array of pixels for that
> slice.
>
> The code is very simple, but there's a problem is with "getProcessor()".
> It doesn't work and I don't know what I'm doing wrong, or if there is
> another way to get the slice without this method.
>
>         ImagePlus imgSource;
>
>         ...
>
>         short inPixels[][] = new short[imgSource.getStack().getSize()][];
>         for (int stack = 0; stack < inPixels.length; stack++) {
>             IJ.write(" *** Stack : " + stack + " / " +
> imgSource.getStack().getSize());
>             inPixels[stack] = (short[])
> imgSource.getStack().getProcessor(stack).convertToShort(true).getPixels();
>         }
>
> I also tried to look at:
> http://rsb.info.nih.gov/ij/source/ij/plugin/filter/Duplicater.java
>
> Sincerelly,
>
> Juanjo Vega.
>
> --
> Juanjo Vega ([hidden email])
>
> Unidad de Biocomputación. Laboratorio B-13.
> Centro Nacional de Biotecnología. CNB-CSIC.
> C\ Darwin, 3. Campus de Cantoblanco.
> Universidad Autónoma de Madrid.
> 28049, Madrid, Spain.
>
> http://www.cnb.csic.es
> http://www.biocomp.cnb.uam.es
>
> +34 91 585 4510
>
>
> "Las mejores almas son capaces de los mayores vicios como de las mayores
> virtudes, y aquellos que caminan despacio por el camino recto pueden
> llegar más lejos que los que corren pero se apartan de él." - Discurso del
> Método, René Descartes.
>