documents:101105ij_r_jython
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| documents:101105ij_r_jython [2011/05/27 14:31] – kota | documents:101105ij_r_jython [2020/11/26 09:11] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | ======= 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. | + | 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:// | ||
| + | |||
| + | * [[http:// | ||
| + | |||
| + | After the installation, | ||
| + | < | ||
| + | R CMD Rserve | ||
| + | </ | ||
| + | |||
| + | Then in the Fiji script editor, try the following code: | ||
| + | |||
| + | <sxh python> | ||
| + | from org.rosuda.REngine.Rserve import RConnection | ||
| + | |||
| + | c = RConnection() | ||
| + | x = c.eval(" | ||
| + | print x.asString() | ||
| + | c.close() | ||
| + | </ | ||
| + | |||
| + | If you see the version number of R printed in the output field, then you are successfully communicating with R from ImageJ. | ||
| + | |||
| + | [[http:// | ||
| + | |||
| + | [[http:// | ||
| + | |||
| + | ====== 2. Using ImageJ from R ====== | ||
| + | |||
| + | One easy way is to execute a shell command to run ImageJ macro / scripts in R. Such example is well documented in the link below. | ||
| + | |||
| + | http:// | ||
| + | |||
| + | I have not made any attempt to directly access ImageJ classes from R but here is my advice for an inquiry. There is an R-package " | ||
| + | |||
| + | < | ||
| + | | ||
| + | |||
| + | http:// | ||
| + | |||
| + | This basically allows use of methods available in one of the classes in ImageJ called ij.IJ | ||
| + | |||
| + | http:// | ||
| + | |||
| + | 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:// | ||
| + | |||
| + | 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. | 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. | ||
| - | Do everything from Java is one way, but python-scripting environment is light enough to test many things. After these testings are done, then a serious Java code could be written. | + | 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. | Here is a trial in win32. All commands will be done from command line. It should basically be similar in other environment. | ||
| Line 66: | Line 131: | ||
| </ | </ | ||
| - | |||
| - | |||
documents/101105ij_r_jython.1306506691.txt.gz · Last modified: 2016/05/24 12:46 (external edit)
