Posted by
Gabriel Lapointe on
Jul 07, 2009; 5:26pm
URL: http://imagej.273.s1.nabble.com/How-can-I-access-to-the-whole-stack-tp3691874p3691875.html
Hello Juanjo,
This is part of a small plugin where I created a 3D array. Pixels get
mapped in a Array[z][x][y] format. I hope it help.
Gabriel Lapointe
public void run(ImageProcessor orig)
{
int w = orig.getWidth();
int h = orig.getHeight();
int z = stack.getSize();
int [][][] Aori = new int[z][w][h];
for (int s = 1; s <= z; s++)
{
imp.setSlice(s);
Aori[s-1]=orig.getIntArray();
}
CleanB(Aori, 0, 255, w, h, z);
CleanW(Aori, 255, 0, w, h, z);
CleanE(Aori, 255, 0, w, h, z);
for (int s = 1; s <= z; s++)
{
imp.setSlice(s);
orig.setIntArray(Aori[s-1]);
}
}
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.
>