3D stack rotation, error message "Stack pixel array null"

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

3D stack rotation, error message "Stack pixel array null"

周鑫
Hello all,

I want to create a 3D stack, which is a rotated version of a first one.
However, when I run the code, an error message appear and say "Stack pixel array null".

Here is my code:
The variable in code called “resStack”, the original image stack is called “is”.
The problem seems to be in the last part of the code.

resStack.setVoxel(x, z, y, is.getVoxel(x, y, z));

When using setVoxel, it did not correctly set the value.

Any idea why this happens?

Best regards, Xin

=====================================================================================

    public static ImageStack StackRotation(ImageStack is, String type)
    {
        int i_width, i_height, i_nslice;
       
        boolean b_ex_x_z = false;

        if (type.equalsIgnoreCase("x<=>z"))
        {
            // keep y axis
            i_height = is.getHeight();
            // exhange x and z
            i_width = is.getSize();
            i_nslice = is.getWidth();
            b_ex_x_z = true;
        }
        else if(type.equalsIgnoreCase("y<=>z"))
        {
            // keep x axis
            i_width = is.getWidth();
            // exhange y and z
            i_height = is.getSize();
            i_nslice = is.getHeight();
        }
        else
        {
            System.err.println("Unknown rotation type: "+type);
            return null;
        }
       
        ImageStack resStack = new ImageStack(i_width, i_height, i_nslice);
       
        for (int z=0; z< i_nslice; z++)
        {      
            for (int x=0; x<i_width; x++)
            {
                for (int y=0; y<i_height; y++)
                {
                    if (b_ex_x_z)
                    {
                        resStack.setVoxel(z, y, x, is.getVoxel(x, y, z));
                    }
                    else
                    {
                        resStack.setVoxel(x, z, y, is.getVoxel(x, y, z));
                    }                  
                }
            }
        }
        return resStack;
    }

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

Re: 3D stack rotation, error message "Stack pixel array null"

Thomas Boudier
Hi,

I think that you have to explicitely create the slices of the stack :

for(int i=0;i<i_nslice;i++) {
  resStack.addSlice("", new ByteProcessor(i_width,i_height));
}

Thomas


Le 15/06/2012 11:36, 周鑫 a écrit :

> Hello all,
>
> I want to create a 3D stack, which is a rotated version of a first one.
> However, when I run the code, an error message appear and say "Stack pixel array null".
>
> Here is my code:
> The variable in code called “resStack”, the original image stack is called “is”.
> The problem seems to be in the last part of the code.
>
> resStack.setVoxel(x, z, y, is.getVoxel(x, y, z));
>
> When using setVoxel, it did not correctly set the value.
>
> Any idea why this happens?
>
> Best regards, Xin
>
> =====================================================================================
>
>      public static ImageStack StackRotation(ImageStack is, String type)
>      {
>          int i_width, i_height, i_nslice;
>
>          boolean b_ex_x_z = false;
>
>          if (type.equalsIgnoreCase("x<=>z"))
>          {
>              // keep y axis
>              i_height = is.getHeight();
>              // exhange x and z
>              i_width = is.getSize();
>              i_nslice = is.getWidth();
>              b_ex_x_z = true;
>          }
>          else if(type.equalsIgnoreCase("y<=>z"))
>          {
>              // keep x axis
>              i_width = is.getWidth();
>              // exhange y and z
>              i_height = is.getSize();
>              i_nslice = is.getHeight();
>          }
>          else
>          {
>              System.err.println("Unknown rotation type: "+type);
>              return null;
>          }
>
>          ImageStack resStack = new ImageStack(i_width, i_height, i_nslice);
>
>          for (int z=0; z<  i_nslice; z++)
>          {
>              for (int x=0; x<i_width; x++)
>              {
>                  for (int y=0; y<i_height; y++)
>                  {
>                      if (b_ex_x_z)
>                      {
>                          resStack.setVoxel(z, y, x, is.getVoxel(x, y, z));
>                      }
>                      else
>                      {
>                          resStack.setVoxel(x, z, y, is.getVoxel(x, y, z));
>                      }
>                  }
>              }
>          }
>          return resStack;
>      }
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
   /**********************************************************/
      Thomas Boudier, MCU Université Pierre et Marie Curie,
      Modélisation Cellulaire et Imagerie Biologique (EE1),
      IFR 83, Bat B 7ème étage, porte 723, Campus Jussieu.
      Tel : 01 44 27 46 92   Fax : 01 44 27 22 91
/*******************************************************/

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