Stack pixel array null exception

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

Stack pixel array null exception

Mohamed Tleis
Dear Members,

In the below code I am trying to add a set of images into an image
stack; but I am getting the following exception:

Exception in thread "main" java.lang.IllegalArgumentException: Stack
pixel array null
     at ij.ImagePlus.setStack(ImagePlus.java:571)
     at ij.ImagePlus.setStack(ImagePlus.java:558)
     at imageProcessing.imageStackTEst.main(imageStackTEst.java:30)
Java Result: 1




import ij.ImagePlus;
import ij.ImageStack;
import java.io.File;

public class imageStackTEst {
     private String path;
     public static void main(String args[])
     {
         String path = "path";

         File file = new File(path);
         File[] images = file.listFiles();

         ImagePlus test = new ImagePlus("/path/sample.tif");
         ImageStack stack = new ImageStack(test.getWidth(),
test.getHeight(), images.length);

         ImagePlus[] imp = new ImagePlus[images.length];
         ImagePlus imp2 = new ImagePlus();

         for (int i =0; i < images.length; i++)
         {
             if (images[i].getAbsolutePath().endsWith(".tif"))
             {
                 imp[i] = new ImagePlus(images[i].getAbsolutePath());
                 stack.addSlice(""+i+"", imp[i].getProcessor());
             }
         }
         imp2.setStack(stack);
         imp2.show();
     }
}

I know I can do it easily for open images; but I am looking to do it for
images without showing them.
(i.e. not to use the IJ.run command)

Can you please feedback on this?


Best Regards,
M. Tleis

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

Re: Stack pixel array null exception

Barry DeZonia
Hi Mohamed,

Change this:

        ImageStack stack = new ImageStack(test.getWidth(),
test.getHeight(), images.length);

To this:
        ImageStack stack = new ImageStack(test.getWidth(),
test.getHeight());


On Fri, Mar 8, 2013 at 11:13 AM, Mohamed Tleis <[hidden email]> wrote:

> Dear Members,
>
> In the below code I am trying to add a set of images into an image stack;
> but I am getting the following exception:
>
> Exception in thread "main" java.lang.**IllegalArgumentException: Stack
> pixel array null
>     at ij.ImagePlus.setStack(**ImagePlus.java:571)
>     at ij.ImagePlus.setStack(**ImagePlus.java:558)
>     at imageProcessing.**imageStackTEst.main(**imageStackTEst.java:30)
> Java Result: 1
>
>
>
>
> import ij.ImagePlus;
> import ij.ImageStack;
> import java.io.File;
>
> public class imageStackTEst {
>     private String path;
>     public static void main(String args[])
>     {
>         String path = "path";
>
>         File file = new File(path);
>         File[] images = file.listFiles();
>
>         ImagePlus test = new ImagePlus("/path/sample.tif");
>         ImageStack stack = new ImageStack(test.getWidth(),
> test.getHeight(), images.length);
>
>         ImagePlus[] imp = new ImagePlus[images.length];
>         ImagePlus imp2 = new ImagePlus();
>
>         for (int i =0; i < images.length; i++)
>         {
>             if (images[i].getAbsolutePath().**endsWith(".tif"))
>             {
>                 imp[i] = new ImagePlus(images[i].**getAbsolutePath());
>                 stack.addSlice(""+i+"", imp[i].getProcessor());
>             }
>         }
>         imp2.setStack(stack);
>         imp2.show();
>     }
> }
>
> I know I can do it easily for open images; but I am looking to do it for
> images without showing them.
> (i.e. not to use the IJ.run command)
>
> Can you please feedback on this?
>
>
> Best Regards,
> M. Tleis
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.**html<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: Stack pixel array null exception

Rasband, Wayne (NIH/NIMH) [E]
In reply to this post by Mohamed Tleis
On Mar 8, 2013, at 12:13 PM, Mohamed Tleis wrote:

> Dear Members,
>
> In the below code I am trying to add a set of images into an image
> stack; but I am getting the following exception:

The easy to open a set of images as a stack without using IJ.run() is to use:

   ImagePlus imp = FolderOpener.open(directory_path);
   imp.show();

-wayne

>
> Exception in thread "main" java.lang.IllegalArgumentException: Stack
> pixel array null
>     at ij.ImagePlus.setStack(ImagePlus.java:571)
>     at ij.ImagePlus.setStack(ImagePlus.java:558)
>     at imageProcessing.imageStackTEst.main(imageStackTEst.java:30)
> Java Result: 1
>
>
>
>
> import ij.ImagePlus;
> import ij.ImageStack;
> import java.io.File;
>
> public class imageStackTEst {
>     private String path;
>     public static void main(String args[])
>     {
>         String path = "path";
>
>         File file = new File(path);
>         File[] images = file.listFiles();
>
>         ImagePlus test = new ImagePlus("/path/sample.tif");
>         ImageStack stack = new ImageStack(test.getWidth(),
> test.getHeight(), images.length);
>
>         ImagePlus[] imp = new ImagePlus[images.length];
>         ImagePlus imp2 = new ImagePlus();
>
>         for (int i =0; i < images.length; i++)
>         {
>             if (images[i].getAbsolutePath().endsWith(".tif"))
>             {
>                 imp[i] = new ImagePlus(images[i].getAbsolutePath());
>                 stack.addSlice(""+i+"", imp[i].getProcessor());
>             }
>         }
>         imp2.setStack(stack);
>         imp2.show();
>     }
> }
>
> I know I can do it easily for open images; but I am looking to do it for
> images without showing them.
> (i.e. not to use the IJ.run command)
>
> Can you please feedback on this?
>
>
> Best Regards,
> M. Tleis
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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