Cluster Multiple Images with ImageJ and R


With Bio7 1.6 it is possible to send multiple images from ImageJ to R without the need to open them in the Graphical User Interface of ImageJ for speed improvements. With a simple script written in Java, Groovy or BeanShell a new Bio7 API command can be used (see below) to transfer images and e.g. to cluster image data with the available packages in R.

ImageMethods.imageToR(“currentImage”, true, 3, imp);  //The first argument is the transfer name of the image, the second argument creates a matrix if true (for datatype double and RGB transfer), the third argument determines the datatype for the transfer (byte, integer, double or RGB), the last argument expects an ImageJ image (can be opened with the ImageJ API) or if null transfers the current opened image in the Bio7 ImageJ panel (API).

The R commands itself can be embedded easily with the available Bio7 API or called from an external R script with the API. Here is a short video which uses the API to cluster selected images with BeanShell and creates a report of the cluster areas in the spreadsheet of Bio7:

The script for the example can be found here!

Apropos: One reason that Beanshell and Groovy are used as default scripting languages in Bio7 is that they also accept (more or less) the Java syntax by default. Beanshell has the greatest Java compatibility. Some minor Java differences to Groovy are described here. Therefore it is very easy for a Java developer (or a C++ developer) at the beginning to use these scripting languages and if interested profit from the scripting syntax sugar these languages offer. In addition Java files can easily converted to scripting files and vice versa (e.g. for speed improvements).