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

Andrew Niccolai andrew.niccolai at yale.edu
Tue Apr 22 21:18:46 CEST 2008


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?

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




More information about the R-sig-Geo mailing list