======= R + ImageJ =======
Analysis using several tools is a powerful way to deal with complex Image data. We often do this, and here is one small example of taking advantages of ImageJ and R at the same time. There are three ways:
- Use R from ImageJ (Rserve)
- Use ImageJ from R (no description yet)
- Use ImageJ and R from Jython REPL
====== 1. Using R from ImageJ via Rserve ======
In this example, R functions are used from ImageJ via Rserve using Jython scripting.
[[http://www.rforge.net/Rserve/doc.html|Rserve]] is a package that you could install from within R. In addition, you need two jar files in the plugin folder of ImageJ/Fiji.
* [[http://www.rforge.net/Rserve/files/|Rserve downloads]]
After the installation, Rserve is an independent program so you could directly start it from the commandline (Rserve is a server that waits for commands, exectutes them and return the output) by:
R CMD Rserve
Then in the Fiji script editor, try the following code:
RImageJ: http://romainfrancois.blog.free.fr/index.php?category/R-package/RImageJ This basically allows use of methods available in one of the classes in ImageJ called ij.IJ http://rsbweb.nih.gov/ij/developer/api/ij/IJ.html This class IJ is a kind of utility class with many static methods that allows user to operate on images like ImageJ macro (especially the **run()** method does sort of such). Access is limited, but depending on what you want to do, I could maybe advice more. Another option is to access at much lower level using rJava: http://www.rforge.net/rJava/index.html By adding ImageJ to your Java path, it's probably possible to write script in R like Rhino javascript or Jython.====== 3. Using ImageJ and R from Jython Interactive Interpreter ====== ImageJ classes could be accessed by Jython, a python based java interface. R has rJava (JRI, Java - R Interface). For this reason, one way of using ImageJ functions and R functions in an integrated environment is to use these resources from Jython. Python-scripting environment is light enough to test many things. After these testings are done, then a serious Java code could be written. Here is a trial in win32. All commands will be done from command line. It should basically be similar in other environment. ===== Setting Up Environment. ===== You should have done: * [[http://rosuda.org/rJava/|rJava]] package should be installed in R. * [[http://www.jython.org/|jython.jar]] should be somewhere locally. **1. set CLASSPATH** Following three jars should be in your classpath. * JRI.jar * REngine.jar * JRIEngine.jar * ij.jar ... so in command line
set CLASSPATH=%CLASSPATH%;C:\Program Files\R\R-2.12.0\library\rJava\jri\JRI.jar;C:\Program Files\R\R-2.12.0\library\rJava\jri\REngine.jar;C:\Program Files\R\R-2.12.0\library\rJava\jri\JRIEngine.jar;C:\ImageJ2\ij.jar
**2. set PATH**
R native libraries should be linked. Then the path should be added with bin, jri, R.dll and JVM.dll:
set PATH=%PATH%;C:\Program Files\R\R-2.12.0\bin;C:\Program Files\R\R-2.12.0\library\rJava\jri;C:\Program Files\R\R-2.12.0\bin\i386;C:\Program Files\Java\jre6\bin\client
===== Example Scripting =====