Login  Register

Re: Problem with PlugIn

Posted by Unruh, Jay on Apr 23, 2008; 2:35pm
URL: http://imagej.273.s1.nabble.com/Problem-with-PlugIn-tp3696466p3696468.html

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