Java: How to get the backing data for a stack slice

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

Java: How to get the backing data for a stack slice

Robert Lockwood
I need to examine pixels in images in stacks, row-by-row, but don't know
how to get the image data.
The code snippet below works up to the for loop:

    public void processStack(final File dFile) {
        ImageStack inStack =
ij.IJ.openImage(dFile.getPath()).getImageStack();
        System.out.println("Stack: " + dFile.getPath() + " stacks = " +
inStack.getSize());
        final int NROWS = inStack.getHeight();
        final int NCOLS = inStack.getHeight();
        final int NSLICES = inStack.getSize();
        for(int slice = 1; slice <= NSLICES; slice++) {
            // float[] image = ???
        }
    }
TIA

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Java: How to get the backing data for a stack slice

Wayne Rasband-2
> On Apr 2, 2019, at 11:17 AM, Robert Lockwood <[hidden email]> wrote:
>
> I need to examine pixels in images in stacks, row-by-row, but don't know
> how to get the image data.

Use the ImageStack.getVoxel(x,y,z) method. Here is a JavaScript example:

  img = IJ.createImage("Untitled", "16-bit ramp", 10, 10, 5);
  stack = img.getStack();
  for (z=0; z<img.getStackSize(); z++)
    for (y=0; y<img.getHeight(); y++)
       for (x=0; x<img.getWidth(); x++)
          IJ.log(x+","+y+","+z+"="+stack.getVoxel(x,y,z));  

-wayne


> The code snippet below works up to the for loop:
>
>    public void processStack(final File dFile) {
>        ImageStack inStack =
> ij.IJ.openImage(dFile.getPath()).getImageStack();
>        System.out.println("Stack: " + dFile.getPath() + " stacks = " +
> inStack.getSize());
>        final int NROWS = inStack.getHeight();
>        final int NCOLS = inStack.getHeight();
>        final int NSLICES = inStack.getSize();
>        for(int slice = 1; slice <= NSLICES; slice++) {
>            // float[] image = ???
>        }
>    }
> TIA
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Java: How to get the backing data for a stack slice

Robert Lockwood
Thank you kindly, Sir!

On Tue, Apr 2, 2019 at 9:46 AM Wayne Rasband <[hidden email]> wrote:

> > On Apr 2, 2019, at 11:17 AM, Robert Lockwood <[hidden email]>
> wrote:
> >
> > I need to examine pixels in images in stacks, row-by-row, but don't know
> > how to get the image data.
>
> Use the ImageStack.getVoxel(x,y,z) method. Here is a JavaScript example:
>
>   img = IJ.createImage("Untitled", "16-bit ramp", 10, 10, 5);
>   stack = img.getStack();
>   for (z=0; z<img.getStackSize(); z++)
>     for (y=0; y<img.getHeight(); y++)
>        for (x=0; x<img.getWidth(); x++)
>           IJ.log(x+","+y+","+z+"="+stack.getVoxel(x,y,z));
>
> -wayne
>
>
> > The code snippet below works up to the for loop:
> >
> >    public void processStack(final File dFile) {
> >        ImageStack inStack =
> > ij.IJ.openImage(dFile.getPath()).getImageStack();
> >        System.out.println("Stack: " + dFile.getPath() + " stacks = " +
> > inStack.getSize());
> >        final int NROWS = inStack.getHeight();
> >        final int NCOLS = inStack.getHeight();
> >        final int NSLICES = inStack.getSize();
> >        for(int slice = 1; slice <= NSLICES; slice++) {
> >            // float[] image = ???
> >        }
> >    }
> > TIA
> >
> > --
> > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html