using ImageJ from R: the RImageJ package
By romain francois on Monday, June 22 2009, 14:57 - RImageJ - Permalink
I've pushed to CRAN the initial version of the RImageJ package. ImageJ is a java based image processing and analysis platform
This version of the package creates an instance of the IJ class as the IJ
object in R, so that many methods of this class can be called using the dollar expansion of rJava.
Here is a simple example that uses the package:
download.file( "http://www.google.fr/intl/en_en/images/logo.gif", dest = "google.gif" ) image = IJ$openImage( "google.gif" ) image$show() IJ$run( "8-bit" ) IJ$run( "Invert" ) IJ$save( "bw-google.gif" ) image$close()
This downloads the google logo, convert it to black and white and inverts it
Future plans for this package contain:- integration of imagej and javagd
- integration of the imagej macro recorder so that it creates R code instead of code in the imagej macro language
Comments
Hello,
Trying to use RImageJ on MacOS 10.5.7, I get the error "Apple AWT Java VM was loaded on first thread -- can't start AWT." when trying to execute the example.
Any idea what it is ?
Thanks
Jean
> library(RImageJ)#
Le chargement a n'ecessit'e le package : rJava
ImageJ version : 1.42n
> download.file( "http://www.google.fr/intl/en_en/ima...", dest = "google.gif" )
essai de l'URL 'http://www.google.fr/intl/en_en/ima...
Content type 'image/gif' length 8558 bytes
URL ouverte
==================================================
downloaded 8558 bytes
> image = IJ$openImage( "google.gif" )
2009-07-10 10:14:34.924 R87902:60b Apple AWT Java VM was loaded on first thread -- can't start AWT.
> sessionInfo()
R version 2.9.1 (2009-06-26)
i386-apple-darwin8.11.1
locale:
fr_FR/fr_FR/fr_FR/C/fr_FR/fr_FR
attached base packages:
1 stats graphics grDevices utils datasets methods base
other attached packages:
1 RImageJ_0.0-142 rJava_0.6-3
loaded via a namespace (and not attached):
1 grid_2.9.1 lattice_0.17-25
>
I get the same error with a nearly identical configuration.
"Attempt to apply non function" when trying to execute an IJ function:
(Windows XP, R 2.9.0, Java 6)
> library('RImageJ')
> download.file( "http://www.google.fr/intl/en_en/ima...", dest = "google.gif" )
trying URL 'http://www.google.fr/intl/en_en/ima...
Content type 'image/gif' length 8558 bytes
opened URL
downloaded 8558 bytes
> image = IJ$openImage( "google.gif" )
> image$show()
Error: attempt to apply non-function
> IJ$run( "8-bit" )
NULL
> IJ$run( "Invert" )
NULL
> image$close()
Error: attempt to apply non-function
I was able to get the demo script to work by replacing image = IJ$openImage( "google.gif" )
with
image = IJ$openImage( "myImage.jpg" )
where myImage.jpg is a jpeg image I happen to have in the active R directory. I was unable to open "google.gif" directly in ImageJ. Perhaps IJ$openImage doesn't work with gif images.
For the first problem, I am not sure what is causing it, and do not have a mac to test it on. It might be worth asking the question on the sig for mac R users: https://stat.ethz.ch/mailman/listin...
Have you tried within JGR ? It might make a difference since in that case the jvm is started first as opposed to started from R.
Yes indeed, it works with JGR.
Thanks
Hello Romain ,
I also have some code which integrates R and ImageJ but I am just a beginner in R so I think it worths combining our efforts. Where can I get the source of your plugin/inerface?
best regards,
Dimiter Prodanov
Great. The package is maintained in r-forge here:
http://r-forge.r-project.org/projec...
If you have a login on r-forge, then please request to join the project.
Romain
I have successfully installed RImageJ and run the example code. I am only a casual ImageJ user, but experienced R user. How can additional functionality, via ImageJ plugins, be accessed through this R package?
cheers...
Brandon
Romain,
Is there a list of all available ImageJ functionality in the current version of this package? I cannot find this information in the current documentation. I have found additional functions that work via trial-and-error; e.g.,
IJ$run("RGB Color") # assuming "8-bit Color" gif
IJ$run("Smooth")
IJ$run("Add Noise")
IJ$save("newfilename.gif")
However, it is unclear how to provide additional arguments when necessary; e.g.,
IJ$run("8-bit Color")
brings up a dialog box requesting an additional parameter. When I use the command
IJ$run("8-bit Color", "2")
the dialog box does not appear, but the second variable is ignored and the default value ("256") appears to be used.
Thanks in advance for your help.
Brandon
... at the moment, the only thing that the package does is create the IJ object, and then it is a case of looking at the methods of the IJ class the way you did.
I would also describe myself as a casual ImageJ user and just though it was a bit more convenient for me to have it running at the R command line.
I have not though yet on how to use additional ImageJ plugins, I would probably start by looking at the Changing Location of Plugins Directory part of this page
Romain