Problem with PlugIn

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

Problem with PlugIn

Sebastian Rhode-2
Hi all,

I am pretty new to Java and may need your help (so my problem may be a
simple one). Here is part of the code

...
ImagePlus imp_dst = WindowManager.getImage(wList[file0]);
ImageStack imst_dst = imp_dst.getStack();
double[] pixels;
...
// get the pixels of each slice in the stack
for (int i=1; i<=imst_dst.getSize(); i++) {
   pixels = (double[]) imst_dst.getPixels(i);
...

The PlugIn compiles without any Problem. The stack which is open contains
four 16bit pictures (512x512). I get the follwong error meassage:

     java.lang.ClassCastException: [S cannot be cast to [D
    at calcCCD_noise3.run(calcCCD_noise3.java:73)
    at ij.IJ.runUserPlugIn(IJ.java:158)
    at ij.ImageJ.runUserPlugIn(ImageJ.java:232)
    at ij.plugin.PlugInExecuter.run(Compiler.java:239)
    at java.lang.Thread.run(Unknown Source)

I am using ImageJ 1.40g and Java 1.6.0_04. Any ideas?

Thanks,

Sebastian
Reply | Threaded
Open this post in threaded view
|

Re: Problem with PlugIn

Unruh, Jay
Sebastian,

You can't type cast arrays.  imst_dst.getPixels(i) returns array type short[] which you are trying to cast into a double[] array type.  The easiest way to fix this is to convert your images to 32-bit and then cast them as float[] (because they are float[]) when you run the getPixels method.

Jay

-----Original Message-----
From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Sebastian Rhode
Sent: Wednesday, April 23, 2008 9:30 AM
To: [hidden email]
Subject: Problem with PlugIn

Hi all,

I am pretty new to Java and may need your help (so my problem may be a simple one). Here is part of the code

...
ImagePlus imp_dst = WindowManager.getImage(wList[file0]);
ImageStack imst_dst = imp_dst.getStack(); double[] pixels; ...
// get the pixels of each slice in the stack for (int i=1; i<=imst_dst.getSize(); i++) {
   pixels = (double[]) imst_dst.getPixels(i); ...

The PlugIn compiles without any Problem. The stack which is open contains four 16bit pictures (512x512). I get the follwong error meassage:

     java.lang.ClassCastException: [S cannot be cast to [D
    at calcCCD_noise3.run(calcCCD_noise3.java:73)
    at ij.IJ.runUserPlugIn(IJ.java:158)
    at ij.ImageJ.runUserPlugIn(ImageJ.java:232)
    at ij.plugin.PlugInExecuter.run(Compiler.java:239)
    at java.lang.Thread.run(Unknown Source)

I am using ImageJ 1.40g and Java 1.6.0_04. Any ideas?

Thanks,

Sebastian
Reply | Threaded
Open this post in threaded view
|

Re: Problem with PlugIn

Michael Schmid
In reply to this post by Sebastian Rhode-2
Hi Sebastian,

the pixels array is never double[].

For 8-bit images it is byte[], for 16-bit short[], for RGB int[]
and for 32-bit float[].

Michael
________________________________________________________________

On 23 Apr 2008, at 16:29, Sebastian Rhode wrote:

> Hi all,
>
> I am pretty new to Java and may need your help (so my problem may be a
> simple one). Here is part of the code
>
> ...
> ImagePlus imp_dst = WindowManager.getImage(wList[file0]);
> ImageStack imst_dst = imp_dst.getStack();
> double[] pixels;
> ...
> // get the pixels of each slice in the stack
> for (int i=1; i<=imst_dst.getSize(); i++) {
>    pixels = (double[]) imst_dst.getPixels(i);
> ...
>
> The PlugIn compiles without any Problem. The stack which is open  
> contains
> four 16bit pictures (512x512). I get the follwong error meassage:
>
>      java.lang.ClassCastException: [S cannot be cast to [D
>     at calcCCD_noise3.run(calcCCD_noise3.java:73)
>     at ij.IJ.runUserPlugIn(IJ.java:158)
>     at ij.ImageJ.runUserPlugIn(ImageJ.java:232)
>     at ij.plugin.PlugInExecuter.run(Compiler.java:239)
>     at java.lang.Thread.run(Unknown Source)
>
> I am using ImageJ 1.40g and Java 1.6.0_04. Any ideas?
>
> Thanks,
>
> Sebastian