ClassCastException when casting to FloatProcessor

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

ClassCastException when casting to FloatProcessor

Mohamed Tleis
Dear members of the list,

I am trying to cast an image processor to a float processor in my java
application; but unfortunately I am getting the following error at run time.

Exception in thread "Run$_main" java.lang.ClassCastException:
ij.process.ByteProcessor cannot be cast to ij.process.FloatProcessor

Here is what I tried to demostrate my problem, probably I am missing some
concepts; and i would appreciate any tutorials or examples you have:

public class test {
    private ImagePlus imp = new ImagePlus("/somepath/testing.tif");
    private ImageProcessor ip = imp.getProcessor();

    public test()    {
        FloatProcessor ipf = (FloatProcessor)ip;    }
    public static void main(String args[])
    {        new test();  }
}

_______________________________________________________

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

Re: ClassCastException when casting to FloatProcessor

Robert Dougherty
Mohammed,

You have to convert the ByteProcessor into a FloatProcessor before you can successfully cast the object as a FloatProcessor.  This can be done with ip.convertToFloat().

import ij.*;
import ij.plugin.PlugIn;
import ij.process.*;
public class Test_ implements PlugIn {
        public void run(String arg){
                ImagePlus imp = IJ.openImage("http://rsb.info.nih.gov/ij/images/blobs.gif");
                ImageProcessor ip = imp.getProcessor();
                FloatProcessor ipf = (FloatProcessor)ip.convertToFloat();
                (new ImagePlus("32-bit version",ipf)).show();
        }
 }

Bob

On Jun 3, 2012, at 8:49 AM, Mohammed Tlais wrote:

> Dear members of the list,
>
> I am trying to cast an image processor to a float processor in my java
> application; but unfortunately I am getting the following error at run time.
>
> Exception in thread "Run$_main" java.lang.ClassCastException:
> ij.process.ByteProcessor cannot be cast to ij.process.FloatProcessor
>
> Here is what I tried to demostrate my problem, probably I am missing some
> concepts; and i would appreciate any tutorials or examples you have:
>
> public class test {
>    private ImagePlus imp = new ImagePlus("/somepath/testing.tif");
>    private ImageProcessor ip = imp.getProcessor();
>
>    public test()    {
>        FloatProcessor ipf = (FloatProcessor)ip;    }
>    public static void main(String args[])
>    {        new test();  }
> }
>
> _______________________________________________________
>
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

Robert P. Dougherty
President
OptiNav, Inc.
1414 127th Pl NE #106
Bellevue, WA 98005
(425) 891-4883
FAX (425) 467-1119
[hidden email]
www.optinav. com

_______________________________________________________

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