[R-sig-Geo] Using rJava with ImageJ plugin

Roger Bivand Roger.Bivand at nhh.no
Wed Apr 23 15:27:30 CEST 2008


On Tue, 22 Apr 2008, Andrew Niccolai wrote:

> I have written a very simple ImageJ plugin using Java code:
>
> import ij.*;
> import ij.process.*;
> import ij.gui.*;
> import java.awt.*;
> import ij.plugin.*;
>
> public class My_Skel implements PlugIn {
>
> 	public void run(String arg) {
> 		IJ.run("Make Binary");
> 		IJ.run("Skeletonize");
> 	}
>
> }
>
>
> As long as an image is open, this plugin first converts any image to a
> binary image and then uses a skeletonization operation on it.  Inside R I
> run the following code,
>
> library(rJava) #load the rJava library
> .jinit(classpath="c:/liao_all/importance_sampling/java",parameters="-Xmx512m
> ")
> #the above is to load the Java virtual
> machine,"c:/liao_all/importance_sampling/java" is where the java code is.
>
> #now you can call the Java method as
> z=.jcall("My_Skel", "[I", "c:/temp/test.tif")
> #z stores the result
> image(z)
>
>
> I get the following error message:
> Exception in thread "main" Error in .jcall("My_Skel", "[I",
> "c:/temp/test.tif") :
>  RcallMethod: cannot determine object class.
>
> I get the same error message when I replace "c:/temp/test.tif", with the
> SpatialGridDataFrame object that was created from the .tif file.
>
> This java code works when I run it through ImageJ but it doesn't work when I
> attempt to call it in R.  Can someone please explain what I am calling
> incorrectly in .jcall?

Windows, right? No idea, can you use system() instead of rJava? I haven't 
bothered to make it work on any Linux platforms. I have not seen any 
results suggesting that anyone has reflected S4 sp classes to Java, so I 
guess using system() and files simplifies things enough to keep them 
working.

My rJava attempts strand on your choice of wrong Java version/wrong class 
path/etc., and have been so painful to debug that I've not found them 
fruitful to continue. On the other hand (D)COM seems to be very reliable 
on Windows, including (D)COM from Python giving a working alternative to 
Rpy on Windows.

Roger

>
> Ultimately, I'd like to point to a .tif image in R and have the java code
> execute and return a new skeletonized .tif image.  Thanks for any help!
>
>
> Andrew Niccolai
> Doctoral Candidate
> Yale School of Forestry
>
>
>
>
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no




More information about the R-sig-Geo mailing list